<?php

namespace Modules\Employee\Http\Requests\Employee;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Modules\Core\Enums\StatusEnum;
use Modules\Core\Traits\FailedValidation;
use Modules\Employee\Services\EmployeeService;

class ReactivateEmployeeRequest extends FormRequest
{
    use FailedValidation;

    protected $employeeService;

    public function __construct(EmployeeService $employeeService)
    {
        $this->employeeService = $employeeService;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        $empId = $this->route('employee');
        $employee = $this->employeeService->find($empId);
        $isRequired = $employee->hasUserAccount() ? 'required' : 'nullable';
        
        return [
            'user_status' => [
                $isRequired,
                Rule::enum(StatusEnum::class),
            ]
        ];
    }

    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }
}
