<?php

declare(strict_types=1);

namespace Cin\Quickpurchase;

final class Config
{
  private static string $envFile = __DIR__.'/../env.json';

  public static function create(): array
  {
    $cfg = [];
    if (file_exists(self::$envFile)) {
      $cfg = json_decode(file_get_contents(self::$envFile), true);
    } elseif ( ! \defined('DB_HOST')) {
      require \dirname(__DIR__, 3).'/includes/config.JTL-Shop.ini.php';
      $cfg = [
        'host' => DB_HOST,
        'name' => DB_NAME,
        'user' => DB_USER,
        'pass' => DB_PASS
      ];
    } elseif (\defined('DB_HOST')) {
      $cfg = [
        'host' => DB_HOST,
        'name' => DB_NAME,
        'user' => DB_USER,
        'pass' => DB_PASS
      ];
    }

    return $cfg;
  }
}
