<?php

namespace Modules\HR\Http\Requests\HolidayAllowance;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Modules\Core\Enums\StatusEnum;
use Modules\Core\Traits\FailedValidation;
use Modules\HR\Enums\CalculationTypeEnum;

class StoreHolidayAllowancePolicyRequest extends FormRequest
{
    use FailedValidation;
    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'name' => [
                'required',
                'string',
                'max:255',
                'unique:holiday_allowance_policies,name',
            ],
            'calculation_type' => [
                'required',
                'string',
                Rule::in(CalculationTypeEnum::casesAsArray()),
            ],
            'amount' => [
                'required_if:calculation_type,' . CalculationTypeEnum::FIXED,
                'prohibited_unless:calculation_type,' . CalculationTypeEnum::FIXED,
            ],

            'multiplier' => [
                'required_if:calculation_type,' . CalculationTypeEnum::MULTIPLIER . ',' . CalculationTypeEnum::DAILY_BASIC,
                'prohibited_if:calculation_type,' . CalculationTypeEnum::FIXED,
            ],
            'status' => [
                'required',
                'string',
                Rule::in(StatusEnum::casesAsArray()),
            ],
        ];
    }

    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }
}
