<?php

declare(strict_types=1);

namespace App\Http\Requests\Invoice;

use App\Http\Requests\Concerns\NormalizesBooleanQueryParams;
use Illuminate\Foundation\Http\FormRequest;

class InvoiceListRequest extends FormRequest
{
    use NormalizesBooleanQueryParams;

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

    public function rules(): array
    {
        return [
            'project_id' => ['nullable', 'integer', 'exists:projects,id'],
            'status' => ['nullable', 'string'],
            'type' => ['nullable', 'in:income,expense'],
            'search' => ['nullable', 'string', 'max:255'],
            'from' => ['nullable', 'date'],
            'to' => ['nullable', 'date', 'after_or_equal:from'],
            'page' => ['nullable', 'integer', 'min:1'],
            'per_page' => ['nullable', 'integer', 'min:1', 'max:50'],
            'noPaginate' => ['nullable', 'boolean'],
        ];
    }

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