<?php

use KimaAI\Logger;
use KimaAI\Main as KimaaiMain;

/**
 * Retrieves the main instance.
 *
 * @return KimaaiMain The main instance.
 * @throws Exception
 */
function KimaAI(): KimaaiMain {
  // phpcs:enable

  static $main;

  if ($main === null) {
    $main = new KimaaiMain();
    $main->load();
  }

  return $main;
}

if (!function_exists('kimaai_log')) {

  /**
   * Helper method for using the logger without importing the class, e.g. from global scope or other plugins.
   *
   * @param string $msg The message to log.
   * @param string $level The message level.
   * @return void
   */
  function kimaai_log(string $msg, string $level = 'info'): void {
    $level = strtolower($level);

    if (!method_exists(Logger::class, $level)) {
      $level = 'info';
    }

    Logger::$level($msg);
  }
}
