<?php

namespace App\Modules\HR\EmployeeSelfService\Controllers;

use App\Http\Controllers\Controller;
use App\Modules\Admin\Tenancy\Models\Tenant;
use App\Modules\HR\EmployeeSelfService\Requests\MeAttendanceIndexRequest;
use App\Modules\HR\EmployeeSelfService\Services\MeTeamAttendanceService;
use App\Modules\HR\EmployeeSelfService\Services\SelfEmployeeContextService;
use Illuminate\View\View;

class MeTeamAttendanceController extends Controller
{
    public function __construct(
        private readonly SelfEmployeeContextService $context,
        private readonly MeTeamAttendanceService $teamAttendance,
    ) {}

    public function index(MeAttendanceIndexRequest $request): View
    {
        $this->authorize('self_service.team_attendance');
        $page = $this->teamAttendance->page($this->tenant(), $this->context->employee(), $request);

        return view('pages.me.attendance.team', $page);
    }

    private function tenant(): Tenant
    {
        $tenant = auth()->user()?->tenant;
        abort_if($tenant === null, 403);

        return $tenant;
    }
}
