<?php

namespace App\Models;

use CodeIgniter\Model;

class SettingModel extends Model
{
    protected $table            = 'settings';
    protected $primaryKey       = 'id';
    protected $useAutoIncrement = true;
    protected $returnType       = 'array';
    protected $allowedFields    = ['key', 'value', 'group'];

    public function getByKey($key)
    {
        return $this->where('key', $key)->first();
    }

    public function getValue($key, $default = null)
    {
        $setting = $this->getByKey($key);
        return $setting ? $setting['value'] : $default;
    }
}
