//
//  SPHttpCenter.h
//  SharedParking
//
//  Created by gui_huan on 2018/3/26.
//  Copyright © 2018年 gui_huan. All rights reserved.
//

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

typedef void(^SuccessWithResult)(id responseObject) ;
typedef void(^FailuerWithReason)(SPRequestError *error);
typedef void(^FormDataHandel)(id<AFMultipartFormData> formData);

typedef NS_ENUM(NSInteger,NetConnection)
{
    SPNoConnect = 0,
    SPPhoneConnect = 1,
    SPWifiConnect =2
};

//返回字段的key值
static NSString *const kRequest_Status = @"succeed";
static NSString *const kRequest_Message = @"error";
static NSString *const kRequest_Data = @"data";

@interface SLHttpCenter : AFHTTPSessionManager

///** 监测到的网络状态/
@property (nonatomic,copy)void (^ConnectStatusBlock)(NetConnection connection);

/**
 判断网络是否正常
 */
@property (nonatomic,assign) BOOL NetWorkIsOK;


/**
 Url
 */
@property (nonatomic, strong)NSString *serverUrl;


/*!
 @method
 @brief 单例初始化工具类
 */
+ (instancetype)SharedInstance;

- (void)postWithUrl:(NSString *)url
          parameter:(id)parameter
            success:(SuccessWithResult)success
            failure:(FailuerWithReason)failure;

- (void)getWithUrl:(NSString *)url
         parameter:(id)parameter
           success:(SuccessWithResult)success
           failure:(FailuerWithReason)failure;


/**
 @param url <#url description#>
 @param body <#body description#>
 @param success <#success description#>
 @param failure <#failure description#>
 */
- (void)postWithUrl:(NSString *)url
               body:(id)body
            success:(SuccessWithResult)success
            failure:(FailuerWithReason)failure;

/**
 数据上传
 灵活程度更高
 @param url <#url description#>
 @param parameter <#parameter description#>
 @param formDataHandel 回调自行构造formData------->更好的方法应该是传一个函数过来
 @param success <#success description#>
 @param failure <#failure description#>
 */
- (void)postWithSubmitUrl:(NSString *)url
                parameter:(NSDictionary *)parameter
           formDataHandel:(FormDataHandel)formDataHandel
                  success:(SuccessWithResult)success
                  failure:(FailuerWithReason)failure;

@end
