<?php

namespace App\Models;

use App\Enums\Currency;
use Illuminate\Database\Eloquent\Model;

class SystemSetting extends Model
{
    protected $fillable = [
        'base_currency',
        'exchange_rate_usd_bob',
        'account_commission_pct',
        'sales_commission_pct',
        'claude_api_key',
        'claude_model',
    ];

    protected function casts(): array
    {
        return [
            'base_currency'          => Currency::class,
            'exchange_rate_usd_bob'  => 'decimal:4',
            'account_commission_pct' => 'decimal:2',
            'sales_commission_pct'   => 'decimal:2',
        ];
    }

    // Singleton: siempre trabaja con el primer registro
    public static function current(): self
    {
        return self::firstOrCreate([], [
            'base_currency'        => 'USD',
            'exchange_rate_usd_bob' => 6.9600,
        ]);
    }
}
