<?php

namespace Modules\Employee\Http\Requests\Designation;

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

class UpdateDesignationRequest extends FormRequest
{
    use FailedValidation;

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'name' => [
                'required',
                'string',
                'max:255',
                Rule::unique('designations', 'name')->ignore($this->route('designation')),
            ],
            'staff_type_id' =>[
                'nullable',
                'integer',
                'exists:staff_types,id',
            ],
            'salary_grade_id' =>[
                'nullable',
                'integer',
                'exists:salary_grades,id',
            ],
            'status' => [
                'required',
                'string',
                Rule::in(StatusEnum::casesAsArray()),
            ],
        ];
    }

    public function attributes(): array
    {
        return [
            'staff_type_id' => 'staff type',
            'salary_grade_id' => 'salary grade',
        ];
    }

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