<?php

namespace App\Modules\HR\Organization\Requests;

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

class UpdateWorkLocationRequest extends FormRequest
{
    use PreparesOrganizationFormData;

    public function authorize(): bool
    {
        return $this->user()?->can('update', $this->route('work_location')) ?? false;
    }

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

        return $rules;
    }
}
