<?php

declare(strict_types=1);

namespace App\Http\Requests\Health;

use App\Http\Requests\Concerns\NormalizesBooleanQueryParams;
use App\Models\HealthTreatment;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class IndexHealthTreatmentRequest extends FormRequest
{
    use NormalizesBooleanQueryParams;

    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'project_id' => ['nullable', 'integer', 'exists:projects,id'],
            'project' => ['nullable', 'string', 'max:120'],
            'product_id' => ['nullable', 'integer', 'exists:products,id'],
            'product' => ['nullable', 'string', 'max:120'],
            'producer_id' => ['nullable', 'integer', 'exists:producers,id'],
            'producer' => ['nullable', 'string', 'max:120'],
            'status' => ['nullable', 'string', Rule::in(array_keys(HealthTreatment::statusOptions()))],
            'include_ended' => ['nullable', 'boolean'],
            'from' => ['nullable', 'date'],
            'to' => ['nullable', 'date', 'after_or_equal:from'],
            'per_page' => ['nullable', 'integer', 'min:1', 'max:50'],
            'noPaginate' => ['nullable', 'boolean'],
        ];
    }

    protected function prepareForValidation(): void
    {
        $this->normalizeBooleanQueryParams(['noPaginate', 'include_ended']);
    }
}
