<?php

namespace App\Modules\HR\Organization\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdateJobGradeRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can('update', $this->route('job_grade')) ?? false;
    }

    public function rules(): array
    {
        $rules = OrganizationRequestRules::for('JobGrade');
        $rules['code'][] = Rule::unique('hr_job_grades', 'code')->where(fn ($q) => $q->where('tenant_id', $this->user()->tenant_id))
            ->ignore($this->route('job_grade')?->id);

        return $rules;
    }
}
