<?php

namespace Khofmann\Config;

use Exception;

class Config
{
  private static array $instances = [];

  private array $app;
  private array $database;

  private function __construct()
  {
    $this->app = require_once __DIR__ . "/../../config/app.php";
    $this->database = require_once __DIR__ . "/../../config/database.php";
  }

  private function __clone()
  {
    throw new Exception("Cannot clone a singleton.");
  }

  private function __wakeup()
  {
    throw new Exception("Cannot unserialize a singleton.");
  }

  private static function getInstance(): Config
  {
    $cls = static::class;
    if (!isset(self::$instances[$cls])) {
      self::$instances[$cls] = new static();
    }

    return self::$instances[$cls];
  }

  public static function getBasePath(): string
  {
    return Config::getInstance()->app["basePath"];
  }

  public static function getBaseFSPath(): string
  {
    return Config::getInstance()->app["baseFSPath"];
  }

  public static function getStoragePath(): string
  {
    return Config::getInstance()->app["storagePath"];
  }

  public static function getDatabase(): array
  {
    return Config::getInstance()->database;
  }
}
