<?php

namespace App\Http\Requests;

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

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

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

        return [
            'patient_id' => ['required', Rule::exists('patients', 'id')->where('tenant_id', $tenantId)],
            'dentist_id' => ['required', Rule::exists('dentists', 'id')->where('tenant_id', $tenantId)],
            'title' => ['required', 'string', 'max:190'],
            'discount_amount' => ['sometimes', 'integer', 'min:0'],
            'notes' => ['nullable', 'string', 'max:2000'],
        ];
    }
}
