<?php

namespace App\Http\Requests\Hr;

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

class StoreLeaveTypeRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->hasPermission('leave.approve') === true;
    }

    public function rules(): array
    {
        return [
            'name' => ['required', 'string', 'max:100'],
            'code' => ['required', 'alpha_dash', 'max:40', Rule::unique('leave_types', 'code')->where('tenant_id', $this->user()->tenant_id)],
            'annual_allocation' => ['nullable', 'numeric', 'min:0', 'max:365'],
            'maximum_carry_forward' => ['nullable', 'numeric', 'min:0', 'max:365'],
            'accrual_method' => ['nullable', Rule::in(['annual', 'monthly', 'none'])],
            'is_paid' => ['nullable', 'boolean'],
            'requires_attachment' => ['nullable', 'boolean'],
            'approval_levels' => ['nullable', 'integer', 'min:1', 'max:2'],
        ];
    }
}
