<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Setting extends Model
{
    protected $table = 'settings';
    
    protected $fillable = [
        'setting_key', 'setting_value', 'setting_type', 'category', 
        'description', 'is_public', 'is_visible', 'is_editable', 'order'
    ];

    protected $casts = [
        'is_public' => 'boolean',
        'is_visible' => 'boolean',
        'is_editable' => 'boolean',
        'order' => 'integer'
    ];

    public $timestamps = true;

    /**
     * Get setting value by key
     */
    public static function get($key, $default = null)
    {
        $setting = self::where('setting_key', $key)->first(); // setting_key ব্যবহার করুন
        return $setting ? $setting->setting_value : $default;
    }

    /**
     * Set setting value
     */
    public static function set($key, $value)
    {
        return self::updateOrCreate(
            ['setting_key' => $key], // setting_key ব্যবহার করুন
            [
                'setting_value' => $value,
                'updated_at' => now()
            ]
        );
    }
}