<?php

namespace App\Http\Controllers\Account;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Services\UserService;
use App\Models\DTO\SearchData;

class LoginLogController extends Controller
{
    private UserService $userService;

    public function __construct(UserService $userService)
    {
        $this->middleware(['front', 'auth']);
        $this->userService = $userService;
    }

    /**
     * 로그인 기록
     * @method GET|POST
     * @see /account/logingLog
     */
    public function index(Request $request)
    {
        $params = SearchData::fromRequest($request);
        $params->startDate = ($request->post('start_date') ?? date('Y-m-d', strtotime('-7 day')));
        $params->endDate = ($request->post('end_date') ?? now()->format('Y-m-d'));

        return view(layout('account.loginLog'), [
            'loginLog' => $this->userService->loginLog(UID, $params),
            'params' => $params,
            'menuID' => 'LOGINLOG'
        ]);
    }
}
