<?php

namespace App\Models;

use App\Models\Concerns\HasUuid;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * A Rechnungskreis: invoice, credit note, cancellation, deposit.
 *
 * Each keeps its own prefix and its own gapless counter, because they are
 * separate number ranges in law as much as in practice — a credit note is not
 * an invoice with a minus sign in front of it.
 */
class InvoiceSeries extends Model
{
    use HasUuid;

    protected $table = 'invoice_series';

    protected $fillable = [
        'kind', 'name', 'prefix', 'yearly_reset', 'digits', 'next_number', 'counter_year', 'active',
    ];

    protected function casts(): array
    {
        return [
            'yearly_reset' => 'boolean',
            'active' => 'boolean',
            'digits' => 'integer',
            'next_number' => 'integer',
            'counter_year' => 'integer',
        ];
    }

    public function invoices(): HasMany
    {
        return $this->hasMany(Invoice::class);
    }
}
