//
//  RTCXConfiguration.h
//  RTCXApiClient
//
//  Created by Apple on 2024/8/15.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/**
 API 通道服务器环境
 */
typedef NS_ENUM(NSInteger, RTCXServerEnviroment) {
    RTCXServerRelease = 0,         ///< 线上
    RTCXServerPreRelease = 1,      ///< 预发，供内部调试使用，外部开发者只能用 RTCXServerRelease
};

@interface RTCXDomain : NSObject
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *domain;
@property (nonatomic, copy) NSString *protocol;
@property (nonatomic, copy) NSString *desc;
@end

@interface RTCXConfigurationConfig : NSObject
@property (nonatomic, copy) NSString* _Nonnull appKey;
@property (nonatomic, copy) NSString* _Nonnull appSecret;
@property (nonatomic, assign) RTCXServerEnviroment appType;
@property (nonatomic, assign) NSInteger regionType;
@property (nonatomic, copy) NSString* _Nullable dnsDomainScheme;// 全量私有化NDS域名Scheme（会拼接在dnsDomain前面），可选，如：https或http
@property (nonatomic, copy) NSString* _Nullable dnsDomain;// 全量私有化NDS域名，可选，如：https://datacenter.example.com
@property (nonatomic,assign) BOOL autoWithAK;// 是否需要在dnsDomain域名前附加AK前缀，默认NO
@property (nonatomic, copy) NSString *privAppKey;// 专属版ak
@property (nonatomic, copy) NSString *privAppSecret;// 专属版as
@property (nonatomic, copy) NSString *privDnsDomain;// 专属版NDS域名
@end

/**
 API 通道配置信息
 */
@interface RTCXConfiguration : NSObject

@property (nonatomic, assign) NSInteger appKeyIndex;

/**
 安全图片的 authCode，不指定时默认为 "07e8"；
 该值必须和安全图片 yw_1222_xxx.jpg 的 xxx 部分一致
 */
@property (nonatomic, copy) NSString *authCode;

/**
 移动应用 appKey，该值自动从安全图片中读取
 */
@property (nonatomic, copy, readonly) NSString *appKey;



@property (nonatomic, copy) NSString *appSecret;

/**
 API 通道官方服务器域名
 */
@property (nonatomic, copy) NSString *host;

/**
 API 通道请求支持的语言，格式标准为：[language designator]-[region designator]，当前支持：en-US，zh-CN，未指定默认使用 zh-CN
 */
@property (nonatomic, copy) NSString *language;

/**
 API 通道服务器环境，不指定时默认为线上
 */
@property (nonatomic, assign, readonly) RTCXServerEnviroment serverEnv;

/**
 API 通道请求超时时间，单位为秒，默认请求超时时间为10秒
 */
@property (nonatomic, assign) NSUInteger timeoutInterval;

///全量降级成HTTP请求
@property (nonatomic, assign, getter=isDemote2Http) BOOL demote2Http;

/**
 API 通道DNS域名
 */
@property (nonatomic, copy, readonly) NSString *dnsDomain;
/**
 region类型 0：国内；1：海外
 */
@property (nonatomic, assign) NSInteger regionType;

@property (nonatomic, strong) NSArray<RTCXDomain*> *domains;

/**
 初始化 API 通道配置信息
 @param host 指定 API 通道服务器域名
 @param serverEnv 指定 API 通道服务器环境
 */
+ (void)initWithHost:(NSString *)host serverEnv:(RTCXServerEnviroment)serverEnv;

+ (void)initWithHost:(NSString *)host serverEnv:(RTCXServerEnviroment)serverEnv appKeyIndex:(NSInteger)appKeyIndex;

+ (void)initWithHost:(NSString *)host serverEnv:(RTCXServerEnviroment)serverEnv appKeyIndex:(NSInteger)appKeyIndex appKey:(NSString*)appKey appSecret:(NSString*)appSecret regionType:(NSInteger )regionType dnsDomainScheme:(nullable NSString*)dnsDomainScheme dnsDomain:(nullable NSString*)dnsDomain autoWithAK:(BOOL)autoWithAK privAppKey:(nullable NSString*)privAppKey privAppSecret:(nullable NSString*)privAppSecret privDnsDomain:(nullable NSString*)privDnsDomain;

+ (void)initWithConfig:(RTCXConfigurationConfig *)config;
/**
 获取Gateway域名，
 @param domainName 网关名称，可传入参数：“gateway”、“stun”、“webH5”
 @param isPrivatized 是否是专属版的
 */
- (NSString *)getGatewayDomain:(NSString *)domainName isPrivatized:(BOOL)isPrivatized;
/**
 判断appKey和appSecret是否有效
 */
- (BOOL)isValidAKAS;
/**
 获取 API 通道配置信息单例，需要先调用方法 `initWithHost:serverEnv:` 进行初始化
 
 @return API 通道配置信息实例
 */
+ (instancetype)sharedInstance;
// 读写regionId
- (void)saveRegionIdToCache:(NSNumber *)regionId;
- (NSNumber *)getCacheRegionId;
- (void)clearRegionIdFromCache;
@end

@interface RTCXConfiguration (privatization)
@property (nonatomic, copy) NSString *privAppKey;
@property (nonatomic, copy) NSString *privAppSecret;
@property (nonatomic, copy) NSString *privHost;
/**
 专属版API 通道DNS域名
 */
@property (nonatomic, copy) NSString *privDnsDomain;

@property (nonatomic, strong) NSArray<RTCXDomain*> *privGatewayDomains;

- (void)setupPrivGatewayDomains:(NSArray *)domains;
/**
 判断privAppKey和privAppSecret是否有效
 */
- (BOOL)isValidPrivAKPrivAS;
@end
NS_ASSUME_NONNULL_END
