<?php

declare(strict_types=1);

namespace Maestro\Core\Modules\Items\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Maestro\Core\Modules\Invoices\Models\VatRate;

class Item extends Model
{
    protected $table = 'maestro_items';

    /**
     * @var list<string>
     */
    protected $fillable = [
        'name',
        'description',
        'default_unit_price_ex_vat',
        'default_vat_rate_id',
        'is_active',
        'sort_order',
    ];

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'default_unit_price_ex_vat' => 'decimal:2',
            'is_active' => 'boolean',
        ];
    }

    /**
     * @return BelongsTo<VatRate, Item>
     */
    public function defaultVatRate(): BelongsTo
    {
        return $this->belongsTo(VatRate::class, 'default_vat_rate_id');
    }
}
