<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

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

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'rule_mode' => ['required', 'in:active,block'],
            'pattern_type' => ['required', 'in:date_range,weekly,monthly,yearly'],

            'start_date' => ['nullable', 'date'],
            'end_date' => ['nullable', 'date'],

            'start_date' => ['nullable', 'date', 'required_if:pattern_type,date_range'],
            'end_date' => ['nullable', 'date', 'required_if:pattern_type,date_range', 'after_or_equal:start_date'],
            'day_of_week' => ['nullable', 'integer', 'between:0,6', 'required_if:pattern_type,weekly'],
            'day_of_month' => ['nullable', 'integer', 'between:1,31', 'required_if:pattern_type,monthly',  'required_if:pattern_type,yearly'],
            'month_of_year' => ['nullable', 'integer', 'between:1,12', 'required_if:pattern_type,yearly'],

            'message' => ['required', 'string'],

            'valid_from' => ['nullable', 'required_unless:pattern_type,date_range', 'date'],
            'valid_until' => ['nullable', 'required_unless:pattern_type,date_range', 'date'],
        ];
    }
}
