<?php

namespace App\Modules\HR\Organization\Requests;

use App\Modules\HR\Organization\Models\JobGrade;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreJobGradeRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can('create', JobGrade::class) ?? 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;
    }
}
