<?php

namespace Sibs\Stargate\Utils;

use Sibs\Stargate\Loggers\SibsLogger;

defined('ABSPATH') || exit;

class SibsEnvironment
{
    protected array $json_file;

    /**
     * Constructor.
     */
    public function __construct()
    {
        $this->json_file = $this->get_json_file();
    }

    /**
     * Get Environments.
     */
    public function get_environments(): array
    {
        return $this->json_file['environments'] ?? [];
    }

    /**
     * Get Base URLS.
     */
    public function get_base_urls(): array
    {
        return $this->json_file['base_urls'] ?? [];
    }

    /**
     * Get Widget Base URLS.
     */
    public function get_widget_base_urls(): array
    {
        return $this->json_file['widget_base_urls'] ?? [];
    }

    /**
     * Get API Version.
     */
    public function get_api_version(): string
    {
        return $this->json_file['api_version'] ?? '';
    }

    /**
     * Get Default Environment.
     */
    public function get_default_environment(): string
    {
        return $this->json_file['default_environment'] ?? '';
    }

    /**
     * Get Json File.
     *
     * @return array
     */
    protected function get_json_file()
    {
        $json_file = '{}';

        try {
            $json_file = file_get_contents(constant('SIBS_PLUGIN_PATH').'environment.json');
        } catch (\Exception $e) {
            SibsLogger::error("Caught exception: {$e->getMessage()}");
        }

        return json_decode($json_file, true);
    }
}
