<?php

declare(strict_types=1);

$envPath = __DIR__ . '/../../.env.php';
$exampleEnvPath = __DIR__ . '/../../.env.example.php';
$crestConfig = is_file($envPath) ? require $envPath : require $exampleEnvPath;
$crestSettingsPath = (string) ($crestConfig['APP_SETTINGS_FILE'] ?? (__DIR__ . '/../../storage/app_settings.php'));
if (is_file($crestSettingsPath)) {
    $storedSettings = require $crestSettingsPath;
    if (is_array($storedSettings)) {
        $storedValues = isset($storedSettings['values']) && is_array($storedSettings['values'])
            ? $storedSettings['values']
            : $storedSettings;
        $crestConfig = array_replace($crestConfig, $storedValues);
    }
}
$clientId = trim((string) ($crestConfig['BITRIX_CLIENT_ID'] ?? ''));
$clientSecret = trim((string) ($crestConfig['BITRIX_CLIENT_SECRET'] ?? ''));

define('C_REST_CLIENT_ID', $clientId);
define('C_REST_CLIENT_SECRET', $clientSecret);
define('C_REST_SCOPE', 'im,imbot,imconnector,imopenlines,lists,user,placement,crm');
define('C_REST_CURRENT_ENCODING', 'UTF-8');
define('C_REST_BLOCK_LOG', true);

return [
    'client_id' => C_REST_CLIENT_ID,
    'client_secret' => C_REST_CLIENT_SECRET,
    'scope' => C_REST_SCOPE,
];
