<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UpdateMedicalRecordRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can('medical_records.edit') ?? false;
    }

    public function rules(): array
    {
        return [
            'recorded_at' => ['required', 'date'],
            'title' => ['nullable', 'string', 'max:255'],
            'chief_complaint' => ['nullable', 'string', 'max:512'],
            'body' => ['nullable', 'string', 'max:65000'],
            'physical_exam' => ['nullable', 'string', 'max:65000'],
            'diagnosis' => ['nullable', 'string', 'max:65000'],
            'treatment' => ['nullable', 'string', 'max:65000'],
            'medications' => ['nullable', 'string', 'max:65000'],
            'weight_kg' => ['nullable', 'numeric', 'min:0', 'max:99999'],
            'temperature_c' => ['nullable', 'numeric', 'min:0', 'max:50'],
            'attachments' => ['nullable', 'array', 'max:10'],
            'attachments.*' => ['file', 'max:10240', 'mimes:jpg,jpeg,png,gif,webp,pdf'],
            'remove_attachment_ids' => ['nullable', 'array'],
            'remove_attachment_ids.*' => ['integer', 'exists:medical_record_attachments,id'],
        ];
    }
}
