//
//  BRNetworkMgr.h
//  TestHttpRequest
//
//  Created by JianjiYuan on 14-11-21.
//  Copyright (c) 2014年 JianjiYuan. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AFNetworking.h>

typedef enum : NSUInteger {
    BRNetMgrDataTypeJSON,
    BRNetMgrDataTypeXML,
    BRNetMgrDataTypeSoap
} BRNetMgrDataType;//请求返回数据类型

typedef enum : NSUInteger {
    BRNetMgrMethodPost,
    BRNetMgrMethodGet,
} BRNetMgrMethod;//请求方式

typedef enum : NSUInteger {
    BRNetMgrFileTypePng,
    BRNetMgrFileTypeJpeg,
} BRNetMgrFileType;//请求方式


#define kFileKeyName       @"FileKeyName"
#define kFilePath          @"FilePath"

#define kDealExtraWhenErrorOcur     @"DealExtraWhenErrorOcur"

@class BRNetworkMgr;

@protocol BRNetworkMgrDelegate <NSObject>

@optional
//非队列异步请求
- (void)httpOperationSuccess:(AFHTTPRequestOperation *)operation
                      result:(NSDictionary *)result;
- (void)httpOperationFailed:(AFHTTPRequestOperation *)operation
                      error:(NSError *)error;

//队列异步请求
- (void)networkQueueComplete:(NSOperationQueue *)queue;

@end

@interface BRNetworkMgr : NSObject

@property (nonatomic, weak) id<BRNetworkMgrDelegate> delegate;
@property (nonatomic, strong) NSOperationQueue *operationQueue;

+ (BRNetworkMgr *)getInstance;//return an instance  not singleton

- (void)startOperation:(NSOperation *)operation;

- (void)addObserverForQueueProgress;
- (void)removeObserverForQueueProgress;

//HTTP请求
- (AFHTTPRequestOperation *)operationWithURL:(NSString *)strURL
                                   interface:(NSString *)interface
                                      params:(NSDictionary *)params
                                    dataType:(BRNetMgrDataType)type
                                      method:(BRNetMgrMethod)method;

//上传文件
- (AFHTTPRequestOperation *)operationUploadWithURL:(NSString *)strURL
                                         interface:(NSString *)interface
                                            params:(NSDictionary *)params
                                          dataType:(BRNetMgrDataType)type
                                          fileType:(BRNetMgrFileType)fileType
                                             files:files;

@end
