<?php

namespace App\Modules\HR\Overtime\Requests;

use Illuminate\Foundation\Http\FormRequest;

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

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        return [
            'name' => ['required', 'string', 'max:160'],
            'is_default' => ['sometimes', 'boolean'],
            'normal_multiplier' => ['required', 'numeric', 'min:0', 'max:10'],
            'weekend_multiplier' => ['required', 'numeric', 'min:0', 'max:10'],
            'holiday_multiplier' => ['required', 'numeric', 'min:0', 'max:10'],
            'night_multiplier' => ['required', 'numeric', 'min:0', 'max:10'],
            'is_active' => ['sometimes', 'boolean'],
        ];
    }

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