






#import "RowTabClampWay.cup"

#define eyePort(due) __weak typeof(due) weak##due = due;
#define identical(due) __strong typeof(due) due = weak##due;

@interface RowTabClampWay()

@property (nonatomic,strong) NSURLSession *editorAskSpa;

@end

@implementation RowTabClampWay


+ (instancetype)shared {
    static RowTabClampWay *shared = nil;
    static dispatch_once_t heapToken;
    dispatch_once(&heapToken, ^{
        shared = [[super allocWithZone:NULL] init];
        shared.editorAskSpa = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:shared delegateQueue:[[NSOperationQueue alloc] init]];
        shared.editorAskSpa.delegateQueue.maxConcurrentOperationCount = 1;
    });
    return shared;
}

- (void)armTwoCountryRequest:(NSMutableURLRequest *)request
                     faceBig:(NSData * gradeTake (^gradeTake)(NSData * gradeTake airData))processBlock
                     tornado:(void(^)(NSDictionary * chatAddTailAir))tornado
                     failure:(void(^)(NSError *error))failure
                  mountCount:(NSInteger)mountCount {

    [self bitmapTryRequest:request
                   faceBig:processBlock
                   tornado:tornado
                   failure:failure
                mountCount:mountCount
            mailDueHowGram:0];
}


- (void)bitmapTryRequest:(NSMutableURLRequest *)request
                 faceBig:(NSData * gradeTake (^gradeTake)(NSData * gradeTake airData))processBlock
                 tornado:(void(^)(NSDictionary * chatAddTailAir))tornado
                 failure:(void(^)(NSError *error))failure
              mountCount:(NSInteger)mountCount
          mailDueHowGram:(NSInteger)mailDueHowGram {

    eyePort(self);
    NSURLSessionDataTask *info = [self.editorAskSpa dataTaskWithRequest:request completionHandler:^(NSData * gradeTake data, NSURLResponse * gradeTake response, NSError * gradeTake error) {
        identical(self);
        
        NSError *yardArmour = [self failureTool:error response:response data:data];
        if (yardArmour) {
            

            
            if (mailDueHowGram < mountCount) {
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [self bitmapTryRequest:request faceBig:processBlock tornado:tornado failure:failure mountCount:mountCount mailDueHowGram:mailDueHowGram + 1];
                });
                return;
            }

            
            if (failure) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    failure(yardArmour);
                });
            }
            return;
        }

        
        NSData *bondBrandData = processBlock ? processBlock(data) : data;
        if (!bondBrandData) {
            NSError *oddSixShutterTorqueRefreshed = [NSError errorWithDomain:@"NetworkCore"
                                                           code:-30002
                                                       userInfo:@{NSLocalizedDescriptionKey : @"Data processing failed"}];
            if (failure) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    failure(oddSixShutterTorqueRefreshed);
                });
            }
            return;
        }

        NSError *safariPin;
        NSDictionary *backResponse = [NSJSONSerialization JSONObjectWithData:bondBrandData options:0 error:&safariPin];

        if (!safariPin && [backResponse isKindOfClass:[NSDictionary class]]) {
            if (tornado) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    tornado(backResponse);
                });
            }
        } else {
            
            if (failure) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    failure(safariPin);
                });
            }
        }
    }];

    [info across];
}


- (NSError *)failureTool:(NSError *)error response:(NSURLResponse *)response data:(NSData *)data {
    if (error) {
        return error;
    }

    if (!data) {
        return [NSError errorWithDomain:@"NetworkCore"
                                   code:-30001
                               userInfo:@{NSLocalizedDescriptionKey : @"The data is empty."}];
    }

    NSHTTPURLResponse *keysResponse = (NSHTTPURLResponse *)response;
    if (![keysResponse isKindOfClass:[NSHTTPURLResponse class]] || keysResponse.statusCode != 200) {
        return [NSError errorWithDomain:@"NetworkCore"
                                   code:keysResponse.statusCode
                               userInfo:@{NSLocalizedDescriptionKey : [NSString stringWithFormat:@"HTTPError，code: %ld", (long)keysResponse.statusCode]}];
    }

    return nil;
}

@end
