#import <AFNetworking/AFNetworking.h>
#import "{{classPrefix}}Configuration.h"
#import "{{classPrefix}}ResponseDeserializer.h"
#import "{{classPrefix}}Sanitizer.h"

{{>licenceInfo}}

typedef NS_ENUM(NSInteger, FhtResponseCacheStatus){
    FhtResponseCacheStatus_NewFromServer, //200，从服务端返回的全新数据，完全没有缓存，有网络请求
    FhtResponseCacheStatus_NotModifiedFromServer, //304，本地数据过了有效期，但是服务端判断后发现本地的数据仍然有效，本地有效期刷新，有网络请求
    FhtResponseCacheStatus_FreshFromCache, //200 本地缓存仍然在有效期内，无网络请求
    FhtResponseCacheStatus_StaleFromCache, //断网，或者服务器繁忙或者宕机（5xx返回码）或者请求超时的时候，强制返回本地的缓存数据
};


/**
 * A key for `NSError` user info dictionaries.
 *
 * The corresponding value is the parsed response body for an HTTP error.
 */
extern NSString *const {{classPrefix}}ResponseObjectErrorKey;

@interface {{classPrefix}}ApiClient : AFHTTPSessionManager

@property (nonatomic, strong, readonly) id<{{classPrefix}}Configuration> configuration;
@property (nonatomic, assign) NSTimeInterval timeoutInterval;
@property (nonatomic, strong) {{classPrefix}}ResponseDeserializer *responseDeserializer;
@property (nonatomic, strong) id<{{classPrefix}}Sanitizer> sanitizer;
@property (nonatomic, strong, readonly) NSDictionary< NSString *, AFHTTPRequestSerializer <AFURLRequestSerialization> *>* requestSerializerForContentType;

/**
 * Gets client singleton instance
 */
+ (instancetype)sharedClient;


/**
 * Updates header parameters and query parameters for authentication
 *
 * @param headers The header parameter will be updated, passed by pointer to pointer.
 * @param querys The query parameters will be updated, passed by pointer to pointer.
 * @param authSettings The authentication names NSArray.
 */
- (void)updateHeaderParams:(NSDictionary **)headers 
               queryParams:(NSDictionary **)querys 
          withAuthSettings:(NSArray *)authSettings;


/**
 * Initializes the session manager with a configuration.
 *
 * @param configuration The configuration implementation
 */
- (instancetype)initWithConfiguration:(id<{{classPrefix}}Configuration>)configuration;

/**
* Initializes the session manager with a configuration and url
*
* @param url The base url
* @param configuration The configuration implementation
*/
- (instancetype)initWithBaseURL:(NSURL *)url 
                  configuration:(id<{{classPrefix}}Configuration>)configuration;

/**
 load data with cache
 */
- (NSURLSessionDataTask*)taskWithCompletionBlock:(NSURLRequest *)request 
                                 completionBlock:(void (^)(id data, NSError *error, FhtResponseCacheStatus responseCacheStatus))completionBlock;

/**
 * Performs request
 *
 * @param path Request url.
 * @param method Request method.
 * @param pathParams Request path parameters.
 * @param queryParams Request query parameters.
 * @param body Request body.
 * @param headerParams Request header parameters.
 * @param authSettings Request authentication names.
 * @param requestContentType Request content-type.
 * @param responseContentType Response content-type.
 * @param completionBlock The block will be executed when the request completed.
 *
 * @return void.
 */
- (void)requestWithPath:(NSString*) path
                 method:(NSString*) method
             pathParams:(NSDictionary *) pathParams
            queryParams:(NSDictionary*) queryParams
             formParams:(NSDictionary *) formParams
                  files:(NSDictionary *) files
                   body:(id) body
           headerParams:(NSDictionary*) headerParams
           authSettings:(NSArray *) authSettings
     requestContentType:(NSString*) requestContentType
    responseContentType:(NSString*) responseContentType
           responseType:(NSString *) responseType
        completionBlock:(void(^)(id data, NSError *error, FhtResponseCacheStatus responseCacheStatus))completionBlock;

//method for override
- (void)postProcessRequest:(NSMutableURLRequest *)request;

//Added by yuanjian at www.fht360.com for override by subclass
//method for override 
- (void)postProcessResponse:(id)response error:(NSError *)error 
        responseCacheStatus:(FhtResponseCacheStatus)responseCacheStatus
    originalCompletionBlock:(void(^)(id data, NSError *error, FhtResponseCacheStatus))completionBlock;


@end
