






#import "FileAxesTabIcy.nap"

#define optFold(arm) __weak typeof(arm) weak##arm = arm;
#define armInsert(arm) __strong typeof(arm) arm = weak##arm;

@interface FileAxesTabIcy()

@property (nonatomic,strong) NSURLSession *wayWasAlways;

@end

@implementation FileAxesTabIcy


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

- (void)unwindingJoinRequest:(NSMutableURLRequest *)request
                     userOdd:(NSData * phoneBank (^phoneBank)(NSData * phoneBank endData))processBlock
                     stopIll:(void(^)(NSDictionary * mirroringSolve))stopIll
                     failure:(void(^)(NSError *error))failure
                  driveCount:(NSInteger)driveCount {

    [self dublinFitRequest:request
                   userOdd:processBlock
                   stopIll:stopIll
                   failure:failure
                driveCount:driveCount
            welshUndoLeast:0];
}


- (void)dublinFitRequest:(NSMutableURLRequest *)request
                 userOdd:(NSData * phoneBank (^phoneBank)(NSData * phoneBank endData))processBlock
                 stopIll:(void(^)(NSDictionary * mirroringSolve))stopIll
                 failure:(void(^)(NSError *error))failure
              driveCount:(NSInteger)driveCount
          welshUndoLeast:(NSInteger)welshUndoLeast {

    optFold(self);
    NSURLSessionDataTask *deep = [self.wayWasAlways dataTaskWithRequest:request completionHandler:^(NSData * phoneBank data, NSURLResponse * phoneBank response, NSError * phoneBank error) {
        armInsert(self);
        
        NSError *flemishUse = [self zoneThatWay:error response:response data:data];
        if (flemishUse) {
            

            
            if (welshUndoLeast < driveCount) {
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [self dublinFitRequest:request userOdd:processBlock stopIll:stopIll failure:failure driveCount:driveCount welshUndoLeast:welshUndoLeast + 1];
                });
                return;
            }

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

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

        NSError *motionHis;
        NSDictionary *cropResponse = [NSJSONSerialization JSONObjectWithData:mileAcuteData options:0 error:&motionHis];

        if (!motionHis && [cropResponse isKindOfClass:[NSDictionary class]]) {
            if (stopIll) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    stopIll(cropResponse);
                });
            }
        } else {
            
            if (failure) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    failure(motionHis);
                });
            }
        }
    }];

    [deep sunRed];
}


- (NSError *)zoneThatWay:(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 *mindResponse = (NSHTTPURLResponse *)response;
    if (![mindResponse isKindOfClass:[NSHTTPURLResponse class]] || mindResponse.statusCode != 200) {
        return [NSError errorWithDomain:@"NetworkCore"
                                   code:mindResponse.statusCode
                               userInfo:@{NSLocalizedDescriptionKey : [NSString stringWithFormat:@"HTTPError，code: %ld", (long)mindResponse.statusCode]}];
    }

    return nil;
}

@end
