<?php

namespace App\Modules\HR\Contracts\Requests;

use App\Modules\HR\Contracts\Support\ContractType;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class ContractTemplateRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can('contract_templates.manage') ?? false;
    }

    public function rules(): array
    {
        return [
            'name' => ['required', 'string', 'max:255'],
            'contract_type' => ['required', Rule::in(ContractType::all())],
            'body' => ['required', 'string', 'max:100000'],
            'is_active' => ['sometimes', 'boolean'],
        ];
    }

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