<?php

declare(strict_types=1);

namespace Maestro\Core\Modules\Invoices\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

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

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        return [
            'customer_id' => ['sometimes', 'required', 'exists:customers,id'],
            'credited_invoice_id' => ['nullable', 'integer', 'exists:invoices,id'],
            'invoice_date' => ['sometimes', 'required', 'date'],
            'expiration_date' => ['sometimes', 'required', 'date'],
            'description' => ['nullable', 'string'],
            'email_body' => ['nullable', 'string'],
            'lines' => ['sometimes', 'array'],
            'lines.*.description' => ['required_with:lines', 'string', 'max:20000'],
            'lines.*.quantity' => ['required_with:lines', 'numeric', 'min:0.0001'],
            'lines.*.unit_price_ex_vat' => ['required_with:lines', 'numeric'],
            'lines.*.vat_rate_id' => ['required_with:lines', 'exists:maestro_vat_rates,id'],
            'lines.*.item_id' => ['nullable', 'integer'],
        ];
    }
}
