<?php

declare(strict_types=1);

namespace Maestro\Core\Modules\Offers\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * Singleton-style row for offer numbering and VAT presets.
 *
 * @property array<int, float>|null $vat_rate_presets
 */
class MaestroOfferSettings extends Model
{
    protected $table = 'maestro_offer_settings';

    /**
     * @var list<string>
     */
    protected $fillable = [
        'number_prefix',
        'number_padding',
        'reset_policy',
        'last_sequence_year',
        'last_sequence',
        'vat_rate_presets',
    ];

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'vat_rate_presets' => 'array',
        ];
    }

    public static function instance(): self
    {
        /** @var self $row */
        $row = static::query()->firstOrCreate([], [
            'number_prefix' => 'OFF',
            'number_padding' => 3,
            'reset_policy' => 'yearly',
            'last_sequence' => 0,
            'vat_rate_presets' => [21.0, 9.0, 0.0],
        ]);

        return $row;
    }
}
