<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
use Hyperf\Codec\Packer\JsonPacker;
use Hyperf\ConfigAliyunAcm\AliyunAcmDriver;
use Hyperf\ConfigApollo\ApolloDriver;
use Hyperf\ConfigApollo\PullMode;
use Hyperf\ConfigCenter\Mode;
use Hyperf\ConfigEtcd\EtcdDriver;
use Hyperf\ConfigNacos\Constants;
use Hyperf\ConfigNacos\NacosDriver;
use Hyperf\ConfigZookeeper\ZookeeperDriver;
use Hyperf\Support\Network;

use function Hyperf\Support\env;

return [
    'enable' => (bool) env('CONFIG_CENTER_ENABLE', true),
    'driver' => env('CONFIG_CENTER_DRIVER', 'apollo'),
    'mode' => env('CONFIG_CENTER_MODE', Mode::PROCESS),
    'drivers' => [
        'apollo' => [
            'driver' => ApolloDriver::class,
            'pull_mode' => PullMode::INTERVAL,
            'server' => 'http://127.0.0.1:9080',
            'appid' => 'test',
            'cluster' => 'default',
            'namespaces' => [
                'application',
            ],
            'interval' => 5,
            'strict_mode' => false,
            'client_ip' => Network::ip(),
            'pullTimeout' => 10,
            'interval_timeout' => 1,
        ],
        'nacos' => [
            'driver' => NacosDriver::class,
            'merge_mode' => Constants::CONFIG_MERGE_OVERWRITE,
            'interval' => 3,
            'default_key' => 'nacos_config',
            'listener_config' => [
                // dataId, group, tenant, type, content
                // 'nacos_config' => [
                //     'tenant' => 'tenant', // corresponding with service.namespaceId
                //     'data_id' => 'hyperf-service-config',
                //     'group' => 'DEFAULT_GROUP',
                // ],
                // 'nacos_config.data' => [
                //     'data_id' => 'hyperf-service-config-yml',
                //     'group' => 'DEFAULT_GROUP',
                //     'type' => 'yml',
                // ],
            ],
            'client' => [
                // nacos server url like https://nacos.hyperf.io, Priority is higher than host:port
                // 'uri' => '',
                'host' => '127.0.0.1',
                'port' => 8848,
                'username' => null,
                'password' => null,
                'guzzle' => [
                    'config' => null,
                ],
                // Only support for nacos v2.
                'grpc' => [
                    'enable' => false,
                    'heartbeat' => 10,
                ],
            ],
        ],
        'aliyun_acm' => [
            'driver' => AliyunAcmDriver::class,
            'interval' => 5,
            'endpoint' => env('ALIYUN_ACM_ENDPOINT', 'acm.aliyun.com'),
            'namespace' => env('ALIYUN_ACM_NAMESPACE', ''),
            'data_id' => env('ALIYUN_ACM_DATA_ID', ''),
            'group' => env('ALIYUN_ACM_GROUP', 'DEFAULT_GROUP'),
            'access_key' => env('ALIYUN_ACM_AK', ''),
            'secret_key' => env('ALIYUN_ACM_SK', ''),
            'ecs_ram_role' => env('ALIYUN_ACM_RAM_ROLE', ''),
        ],
        'etcd' => [
            'driver' => EtcdDriver::class,
            'packer' => JsonPacker::class,
            'namespaces' => [
                '/application',
            ],
            'mapping' => [
                // etcd key => config key
                '/application/test' => 'test',
            ],
            'interval' => 5,
            'client' => [
                # Etcd Client
                'uri' => 'http://127.0.0.1:2379',
                'version' => 'v3beta',
                'options' => [
                    'timeout' => 10,
                ],
            ],
        ],
        'zookeeper' => [
            'driver' => ZookeeperDriver::class,
            'server' => env('ZOOKEEPER_SERVER', '127.0.0.1:2181'),
            'path' => env('ZOOKEEPER_CONFIG_PATH', '/conf'),
            'interval' => 5,
        ],
    ],
];
