<?php

namespace App\Http\Requests;

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

class ScheduleExceptionRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()->can('appointments.manage');
    }

    public function rules(): array
    {
        return [
            'dentist_id' => ['nullable', Rule::exists('dentists', 'id')->where('tenant_id', app(\App\Support\Tenancy::class)->id())],
            'date' => ['required', 'date', 'after_or_equal:today'],
            'type' => ['required', Rule::in(['off', 'extra'])],
            'start_time' => ['required_if:type,extra', 'nullable', 'date_format:H:i'],
            'end_time' => ['required_with:start_time', 'nullable', 'date_format:H:i', 'after:start_time'],
            'reason' => ['nullable', 'string', 'max:190'],
        ];
    }
}
