<?php

namespace App\Http\Requests;

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

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

    public function rules(): array
    {
        return [
            'procedure_id' => ['required', Rule::exists('procedures', 'id')->where('tenant_id', app(Tenancy::class)->id())],
            'tooth' => ['nullable', 'integer', Rule::in(\App\Domain\Clinical\Fdi::all())],
            'surfaces' => ['nullable', 'array'],
            'surfaces.*' => [Rule::in(config('dental.surfaces'))],
            'price' => ['nullable', 'integer', 'min:0', 'max:100000000'],
            'note' => ['nullable', 'string', 'max:190'],
        ];
    }
}
