<?php

namespace Modules\Employee\Http\Requests\SalaryGrade;

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

class UpdateSalaryGradeRequest 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('salary_grades', 'name')->ignore($this->route('salary_grade')),
            ],
            'min_salary' => [
                    'nullable',
                    'numeric',
                    'min:0',
                ],
            'max_salary' => [
                    'nullable',
                    'numeric',
                    'min:0',
                    'gte:min_salary',
                ],
            'status' => [
                'required',
                'string',
                Rule::in(StatusEnum::casesAsArray()),
            ],
        ];
    }
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }
}
