<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * Panel-wide configuration, stored the same way the POS stores per-shop
 * settings so the two feel consistent to maintain.
 */
class CentralSetting extends Model
{
    protected $fillable = ['group', 'key', 'value', 'type'];

    public function typedValue(): mixed
    {
        return match ($this->type) {
            'boolean' => filter_var($this->value, FILTER_VALIDATE_BOOLEAN),
            'integer' => (int) $this->value,
            'float' => (float) $this->value,
            'json' => json_decode((string) $this->value, true) ?? [],
            default => $this->value,
        };
    }
}
