<?php

namespace App\Modules\HR\EmployeeSelfService\Services;

use App\Models\User;
use App\Modules\HR\Employees\Models\Employee;
use Illuminate\Support\Facades\Auth;

class SelfEmployeeContextService
{
    /**
     * Active employee for the authenticated user (never from route parameters).
     */
    public function employee(): Employee
    {
        $user = Auth::user();
        if (! $user instanceof User) {
            abort(403);
        }

        return Employee::query()
            ->where('tenant_id', $user->tenant_id)
            ->whereKey((int) $user->employee_id)
            ->where('is_active', true)
            ->with(['department', 'position'])
            ->firstOrFail();
    }
}
