<?php

namespace App\Modules\HR\EmploymentStatuses\Requests;

use App\Modules\HR\EmploymentStatuses\Models\EmploymentStatus;

class UpdateEmploymentStatusRequest extends StoreEmploymentStatusRequest
{
    public function authorize(): bool
    {
        $status = $this->route('employment_status');

        return $status instanceof EmploymentStatus
            && ($this->user()?->can('update', $status) ?? false);
    }

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        return array_merge($this->baseRules(), [
            'is_active' => ['required', 'boolean'],
        ]);
    }

    protected function prepareForValidation(): void
    {
        $this->merge(['is_active' => $this->boolean('is_active')]);
    }
}
