<?php

namespace App\Http\Requests;

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

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

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

        return [
            'patient_id' => ['required', Rule::exists('patients', 'id')->where('tenant_id', $tenantId)],
            'dentist_id' => ['nullable', Rule::exists('dentists', 'id')->where('tenant_id', $tenantId)],
            'due_date' => ['required', 'date', 'after:today'],
            'reason' => ['required', 'string', 'max:190'],
        ];
    }
}
