<?php

namespace App\Http\Requests;

use Illuminate\Validation\Rule;

class UpdateInvoiceRequest extends StoreInvoiceRequest
{
    public function rules(): array
    {
        $rules = parent::rules();
        $businessId = $this->attributes->get('current_business')?->id;
        $invoice = $this->route('invoice');

        $rules['invoice_number'] = [
            'nullable',
            'string',
            'max:60',
            Rule::unique('invoices', 'invoice_number')
                ->where('business_id', $businessId)
                ->ignore($invoice?->id),
        ];

        return $rules;
    }
}
