<?php

namespace App\Http\Requests;

use App\Models\PatientFile;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

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

    public function rules(): array
    {
        return [
            'file' => [
                'required', 'file', 'max:25600', // 25 MB
                'mimes:jpg,jpeg,png,webp,pdf,dcm',
            ],
            'type' => ['required', Rule::in(PatientFile::TYPES)],
            'teeth' => ['nullable', 'array'],
            'teeth.*' => ['integer', Rule::in(\App\Domain\Clinical\Fdi::all())],
            'caption' => ['nullable', 'string', 'max:190'],
            'treatment_plan_id' => ['nullable', 'integer'],
            'appointment_id' => ['nullable', 'integer'],
        ];
    }
}
