<?php

declare(strict_types=1);

namespace MyCustomizer\WooCommerce\Connector\Config;

use Exception;
use Symfony\Component\Yaml\Yaml;

final class MczrConfig
{
    /** @var array|null */
    private static $config = null;

    /**
     * @throws Exception
     */
    public static function getConfig(): array
    {
        if (self::$config === null) {
            $path = realpath(__DIR__ . '/../../config/config.yml');

            if ($path === false || !is_file($path)) {
                throw new Exception('No config file found');
            }

            $config = Yaml::parse(file_get_contents($path));

            if (!is_array($config)) {
                throw new Exception('Invalid config file');
            }

            self::$config = $config;
        }

        return self::$config;
    }
}
