<?php

namespace App\Controllers\Auth;

use App\DTOs\Auth\LocalDTO;
use App\Entities\UserEntity;
use App\Services\Auth\LocalService;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;

/**
 * @property LocalService $service
 * IDE에게 protected $service 속성이 LocalService 타입임을 알려줍니다.
 */
class LocalController extends AuthController
{
    public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
    {
        parent::initController($request, $response, $logger);
        if ($this->service === null) {
            $this->service = service('localauth');
        }
    }
    //로그인처리
    protected function login_process(): UserEntity
    {
        return $this->service->login(new LocalDTO($this->request->getPost()));
    }
    protected function logout_process(): void
    {
        $this->service->logout();
    }
}
