<?php

namespace App\Http\Requests;

use App\Support\Tenancy;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

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

    public function rules(): array
    {
        $tenantId = app(Tenancy::class)->id();

        return [
            'dentist_id' => ['required', Rule::exists('dentists', 'id')->where('tenant_id', $tenantId)],
            'patient_id' => ['required', Rule::exists('patients', 'id')->where('tenant_id', $tenantId)],
            'starts_at' => ['required', 'date'], // clinic-local "Y-m-d H:i"
            'reason' => ['nullable', 'string', 'max:190'],
        ];
    }
}
