<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class TaxSetup extends Model
{
    protected $table = 'tax_setup';

    protected $fillable = [
        'is_enabled',
        'active_tax_id',
        'updated_by',
    ];

    protected function casts(): array
    {
        return [
            'is_enabled' => 'boolean',
        ];
    }

    /**
     * Get the singleton tax setup configuration.
     */
    public static function current(): static
    {
        return static::firstOrCreate([], [
            'is_enabled' => false,
            'active_tax_id' => null,
        ]);
    }

    public function activeTax(): BelongsTo
    {
        return $this->belongsTo(Tax::class, 'active_tax_id');
    }

    public function updatedBy(): BelongsTo
    {
        return $this->belongsTo(User::class, 'updated_by');
    }
}
