<?php

defined('APP_BOOTSTRAPPED') or exit('No direct access.');

$secretsFile = __DIR__ . '/secrets.php';

if (!is_file($secretsFile)) {
    throw new RuntimeException(
        'File secrets.php tidak ditemukan.'
    );
}

$secrets = require $secretsFile;

if (!is_array($secrets)) {
    throw new RuntimeException(
        'Format secrets.php tidak valid.'
    );
}

return [
    /*
    |--------------------------------------------------------------------------
    | Konfigurasi SGX
    |--------------------------------------------------------------------------
    */

    'sgx' => [
        'base_url' => getenv('SGX_API_URL')
            ?: (
                isset($secrets['sgx']['api_url'])
                    ? trim((string) $secrets['sgx']['api_url'])
                    : ''
            ),

        'agent_code' => getenv('SGX_AGENT_CODE')
            ?: (
                isset($secrets['sgx']['agent_code'])
                    ? trim((string) $secrets['sgx']['agent_code'])
                    : ''
            ),

        'signature' => getenv('SGX_SIGNATURE')
            ?: (
                isset($secrets['sgx']['signature'])
                    ? trim((string) $secrets['sgx']['signature'])
                    : ''
            ),

        'connect_timeout' => 10,
        'timeout'         => 60,
        'force_ipv4'      => true,
    ],

    /*
    |--------------------------------------------------------------------------
    | Konfigurasi Nexus
    |--------------------------------------------------------------------------
    */

    'nexus' => [
        'base_url' => getenv('NEXUS_API_URL')
            ?: (
                isset($secrets['nexus']['api_url'])
                    ? trim((string) $secrets['nexus']['api_url'])
                    : ''
            ),

        'agent_code' => getenv('NEXUS_AGENT_CODE')
            ?: (
                isset($secrets['nexus']['agent_code'])
                    ? trim((string) $secrets['nexus']['agent_code'])
                    : ''
            ),

        'agent_token' => getenv('NEXUS_AGENT_TOKEN')
            ?: (
                isset($secrets['nexus']['agent_token'])
                    ? trim((string) $secrets['nexus']['agent_token'])
                    : ''
            ),

        'connect_timeout' => 10,
        'timeout'         => 60,
        'force_ipv4'      => true,
    ],
];