//
//  ZYJQNConfiguration.h
//  ZYJQiniuSDK
//
//  Created by bailong on 15/5/21.
//  Copyright (c) 2015年 Qiniu. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ZYJQNRecorderDelegate.h"
#import "ZYJQNDns.h"
#import "ZYJQNZone.h"
/**
 * 断点上传时的分块大小
 */
extern const UInt32 kZYJQNBlockSize;

/**
 *  DNS默认缓存时间
 */
extern const UInt32 kZYJQNDefaultDnsCacheTime;

/**
 *    转换为用户需要的url
 *
 *    @param url  上传url
 *
 *    @return 根据上传url算出代理url
 */
typedef NSString * (^ZYJQNUrlConvert)(NSString *url);

@class ZYJQNConfigurationBuilder;
@class ZYJQNZone;
@class ZYJQNReportConfig;

/**
 *    Builder block
 *
 *    @param builder builder实例
 */
typedef void (^ZYJQNConfigurationBuilderBlock)(ZYJQNConfigurationBuilder *builder);

@interface ZYJQNConfiguration : NSObject

/**
 *    存储区域
 */
@property (copy, nonatomic, readonly) ZYJQNZone *zone;

/**
 *    断点上传时的分片大小
 */
@property (readonly) UInt32 chunkSize;

/**
 *    如果大于此值就使用断点上传，否则使用form上传
 */
@property (readonly) UInt32 putThreshold;

/**
 *    上传失败时每个上传域名的重试次数，默认重试3次
 */
@property (readonly) UInt32 retryMax;

/**
 *    重试前等待时长，默认0.5s
 */
@property (readonly) NSTimeInterval retryInterval;

/**
 *    超时时间 单位 秒
 */
@property (readonly) UInt32 timeoutInterval;

/**
 *    是否使用 https，默认为 YES
 */
@property (nonatomic, assign, readonly) BOOL useHttps;

/**
  *   是否开启并发分片上传，默认为NO
  */
@property (nonatomic, assign, readonly) BOOL useConcurrentResumeUpload;

/**
 *   并发分片上传的并发任务个数，在concurrentResumeUpload为YES时有效，默认为3个
 */
@property (nonatomic, assign, readonly) UInt32 concurrentTaskCount;

@property (nonatomic, readonly) ZYJQNReportConfig *reportConfig;

/**
 *    重试时是否允许使用备用上传域名，默认为YES
 */
@property (nonatomic, assign) BOOL allowBackupHost;

@property (nonatomic, readonly) id<ZYJQNRecorderDelegate> recorder;

@property (nonatomic, readonly) ZYJQNRecorderKeyGenerator recorderKeyGen;

@property (nonatomic, readonly) NSDictionary *proxy;

@property (nonatomic, readonly) ZYJQNUrlConvert converter;

+ (instancetype)build:(ZYJQNConfigurationBuilderBlock)block;

@end


#define kZYJQNGlobalConfiguration [ZYJQNGlobalConfiguration shared]
@interface ZYJQNGlobalConfiguration : NSObject

/**
 *   是否开启dns预解析 默认开启
 */
@property(nonatomic, assign)BOOL isDnsOpen;

/**
 *   dns 预取失败后 会进行重新预取  rePreHostNum为最多尝试次数
 */
@property(nonatomic, assign)UInt32 dnsRepreHostNum;

/**
 *   dns预取缓存时间  单位：秒
 */
@property(nonatomic, assign)UInt32 dnsCacheTime;

/**
 *   自定义DNS解析客户端host
 */
@property(nonatomic, strong) id <ZYJQNDnsDelegate> dns;

/**
 *   dns解析结果本地缓存路径
 */
@property(nonatomic,  copy, readonly)NSString *dnscacheDir;

+ (instancetype)shared;

@end


@interface ZYJQNConfigurationBuilder : NSObject

/**
 *    默认上传服务器地址
 */
@property (nonatomic, strong) ZYJQNZone *zone;

/**
 *    断点上传时的分片大小
 */
@property (assign) UInt32 chunkSize;

/**
 *    如果大于此值就使用断点上传，否则使用form上传
 */
@property (assign) UInt32 putThreshold;

/**
 *    上传失败时每个上传域名的重试次数，默认重试3次
 */
@property (assign) UInt32 retryMax;

/**
 *    重试前等待时长，默认0.5s
 */
@property (assign) NSTimeInterval retryInterval;

/**
 *    超时时间 单位 秒
 */
@property (assign) UInt32 timeoutInterval;

/**
 *    是否使用 https，默认为 YES
 */
@property (nonatomic, assign) BOOL useHttps;

/**
 *    重试时是否允许使用备用上传域名，默认为YES
 */
@property (nonatomic, assign) BOOL allowBackupHost;

/**
 *   是否开启并发分片上传，默认为NO
 */
@property (nonatomic, assign) BOOL useConcurrentResumeUpload;

/**
 *   并发分片上传的并发任务个数，在concurrentResumeUpload为YES时有效，默认为3个
 */
@property (nonatomic, assign) UInt32 concurrentTaskCount;

@property (nonatomic, strong) id<ZYJQNRecorderDelegate> recorder;

@property (nonatomic, strong) ZYJQNRecorderKeyGenerator recorderKeyGen;

@property (nonatomic, strong) ZYJQNReportConfig *reportConfig;

@property (nonatomic, strong) NSDictionary *proxy;

@property (nonatomic, strong) ZYJQNUrlConvert converter;

@end
