<?php
namespace nur\sery\db\sqlite;

use nur\sery\php\nur_func;

class _config {
  static function with($configs): self {
    if ($configs instanceof static) return $configs;
    return new static($configs);
  }

  const CONFIG = null;

  function __construct($configs) {
    if ($configs === null) $configs = static::CONFIG;
    if ($configs === null) $configs = [];
    elseif (is_string($configs)) $configs = [$configs];
    elseif (is_callable($configs)) $configs = [$configs];
    elseif (!is_array($configs)) $configs = [strval($configs)];
    $this->configs = $configs;
  }

  /** @var array */
  protected $configs;

  function configure(Sqlite $sqlite): void {
    foreach ($this->configs as $key => $config) {
      if (is_string($config) && !nur_func::is_method($config)) {
        $sqlite->exec($config);
      } else {
        nur_func::ensure_func($config, $this, $args);
        nur_func::call($config, $sqlite, $key, ...$args);
      }
    }
  }
}
