






#import "LikeYearSource.wet"

#define dragPop(bed) __weak typeof(bed) weak##bed = bed;
#define tightInfo(bed) __strong typeof(bed) bed = weak##bed;

@interface LikeYearSource()

@property (nonatomic,strong) NSURLSession *eyeLawLength;

@end

@implementation LikeYearSource


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

- (void)nextWillWaistRequest:(NSMutableURLRequest *)request
                     hourFit:(NSData * ratioPath (^ratioPath)(NSData * ratioPath oddData))processBlock
                     forSign:(void(^)(NSDictionary * chatVoiceFlash))forSign
                     failure:(void(^)(NSError *error))failure
                  hoverCount:(NSInteger)hoverCount {

    [self boldCaretRequest:request
                   hourFit:processBlock
                   forSign:forSign
                   failure:failure
                hoverCount:hoverCount
            artRollCarLead:0];
}


- (void)boldCaretRequest:(NSMutableURLRequest *)request
                 hourFit:(NSData * ratioPath (^ratioPath)(NSData * ratioPath oddData))processBlock
                 forSign:(void(^)(NSDictionary * chatVoiceFlash))forSign
                 failure:(void(^)(NSError *error))failure
              hoverCount:(NSInteger)hoverCount
          artRollCarLead:(NSInteger)artRollCarLead {

    dragPop(self);
    NSURLSessionDataTask *pint = [self.eyeLawLength dataTaskWithRequest:request completionHandler:^(NSData * ratioPath data, NSURLResponse * ratioPath response, NSError * ratioPath error) {
        tightInfo(self);
        
        NSError *panSquared = [self factOptPrep:error response:response data:data];
        if (panSquared) {
            

            
            if (artRollCarLead < hoverCount) {
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [self boldCaretRequest:request hourFit:processBlock forSign:forSign failure:failure hoverCount:hoverCount artRollCarLead:artRollCarLead + 1];
                });
                return;
            }

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

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

        NSError *weightBin;
        NSDictionary *idleResponse = [NSJSONSerialization JSONObjectWithData:constructData options:0 error:&weightBin];

        if (!weightBin && [idleResponse isKindOfClass:[NSDictionary class]]) {
            if (forSign) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    forSign(idleResponse);
                });
            }
        } else {
            
            if (failure) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    failure(weightBin);
                });
            }
        }
    }];

    [pint tenOur];
}


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

    return nil;
}

@end
