<?php

namespace Modules\Employee\Http\Requests\Employee;

use Illuminate\Foundation\Http\FormRequest;
use Modules\Core\Traits\FailedValidation;
use Illuminate\Validation\Rule;

class UpdateEmployeeRequest extends FormRequest
{
    use FailedValidation;

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        $employeeId = $this->route('employee');

        return [
            'name' => ['required', 'string', 'max:255'],
            'emp_number' => [
                'required',
                'string',
                'max:20',
                'regex:/^E\d{6}$/',
                Rule::unique('employees', 'emp_number')->ignore($employeeId),
            ],
            'dob' => ['nullable', 'date'],
            'nid' => [
                'nullable',
                'string',
                'max:20',
                Rule::unique('employees', 'nid')->ignore($employeeId)
            ],
            'father_name' => ['nullable', 'string', 'max:255'],
            'mother_name' => ['nullable', 'string', 'max:255'],
            'gender_id' => ['required', 'exists:genders,id'],
            'religion_id' => ['nullable', 'exists:religions,id'],
            'blood_id' => ['nullable', 'exists:bloods,id'],
            'marital_status_id' => ['nullable', 'exists:marital_statuses,id'],
            'nation_id' => ['nullable', 'exists:countries,id'],
        ];
    }

    public function attributes(): array
    {
        return [
            'emp_number' => 'employee number',
            'blood_id'   => 'blood group',
            'nation_id'  => 'nationality',
        ];
    }

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