<?php

declare(strict_types=1);

namespace App\Http\Requests\Health;

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

class StoreHealthTreatmentUpdateRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'report_at' => ['required', 'date'],
            'progress_percent' => ['required', 'integer', 'min:0', 'max:100'],
            'notes' => ['nullable', 'string'],
            'expert_opinion' => ['nullable', 'string'],
            'written_report' => ['nullable', 'string'],
            'attachments' => ['nullable', 'array'],
            'attachments.*' => ['string', 'max:500'],
            'documents' => ['nullable', 'array'],
            'documents.*' => ['string', 'max:500'],
            'total_cost' => ['nullable', 'numeric', 'min:0'],
            'invoice_image' => ['nullable', 'string', 'max:500'],
            'consumables' => ['nullable', 'array'],
            'consumables.*.name' => ['required_with:consumables', 'string', 'max:255'],
            'consumables.*.unit' => ['nullable', 'string', Rule::in(array_keys(Report::consumableUnitOptions()))],
            'consumables.*.quantity' => ['nullable', 'numeric', 'min:0'],
            'consumables.*.unit_price' => ['nullable', 'numeric', 'min:0'],
            'invoice_items' => ['nullable', 'array'],
            'invoice_items.*.title' => ['required_with:invoice_items', 'string', 'max:255'],
            'invoice_items.*.amount' => ['nullable', 'numeric', 'min:0'],
        ];
    }

    public function messages(): array
    {
        return [
            'report_at.required' => 'تاریخ و زمان پیشرفت الزامی است.',
            'progress_percent.required' => 'درصد پیشرفت درمان الزامی است.',
        ];
    }
}
