<?php
namespace Nibiru\Module\Ai\Traits;

trait Ai
{
    /**
     * Read a config value with a default. Honours nested . keys, e.g.
     *   $this->cfg('chat.model', 'qwen2.5-coder:14b')
     */
    protected function cfg(string $key, $default = null)
    {
        $cfg = $this->config();
        if (isset($cfg->$key)) return $cfg->$key;
        // Allow flat-key INI as written in ai.ini ("chat.model = ..." → "chat.model" key)
        $varname = str_replace('.', '_', $key);
        if (isset($cfg->$varname)) return $cfg->$varname;
        return $default;
    }
}
