<?php

namespace App\Services\Auth;

use App\Entities\UserEntity;
use App\Helpers\AuthHelper;
use App\Models\CommonModel;
use App\Services\CommonService;

abstract class AuthService extends CommonService
{
	protected string $helperClass = AuthHelper::class;

	protected function __construct(CommonModel $model)
	{
		parent::__construct($model);
		$this->addClassPaths('Auth');
	}
	public function getEntityClass(): string
	{
		return UserEntity::class;
	}
	//로그인
	abstract protected function login_process(array $formDatas): UserEntity;
	final public function login(array $formDatas): UserEntity
	{
		$entity = $this->login_process($formDatas);
		//인증 세션처리
		$this->getAuthContext()->setAuthSession($entity);
		return $entity;
	}
	//로그아웃
	final public function logout(): void
	{
		$this->getAuthContext()->destroyAuthSession();
	}
}
