#import "NSObject+HasModel.h"
#import <objc/runtime.h>

@implementation NSObject (HasModel)

+ (instancetype)rangeRedTabIcyDict:(NSDictionary *)hall {
    if (![hall isKindOfClass:[NSDictionary class]]) return nil;
    
    id model = [[self alloc] init];
    
    
    NSArray *fitBlendBurst = [self variationMinSexAmericanHint];
    NSDictionary *eggSchemes = [self lockingDropBriefTamilFusionSlopeName];
    NSDictionary *ninePinRoman = [self advertiseActionLayoutPhaseGopherArray];
    
    for (NSString *propertyName in fitBlendBurst) {
        
        NSString *keyPath = eggSchemes[propertyName] ?: propertyName;
        
        
        id value = [hall valueForKeyPath:keyPath];

        if (!value || [value isKindOfClass:[NSNull class]]) continue;
        
        
        NSString *mainRateType = [self logCookieAssistantRearrangeListenerPipeName:propertyName];
        
        
        value = [self focusFourSexValue:value
                       seeHashUndoName:propertyName
                              keyPath:keyPath
                        mainRateType:mainRateType
                       ninePinRoman:ninePinRoman
                              oneJobDict:hall];
        
        
        if (value) {
            @try {
                [model setValue:value forKey:propertyName];
            } @catch (NSException *exception) {

            }
        }
    }
    return model;
}

+ (NSArray *)seeTerabytesSamplingVowelTryDynamicArray:(NSArray *)dictArray {
    
    if (![dictArray isKindOfClass:[NSArray class]]) return @[];
    
    
    NSMutableArray *frontArray = [NSMutableArray arrayWithCapacity:dictArray.count];
    
    
    for (id element in dictArray) {
        
        if (![element isKindOfClass:[NSDictionary class]]) {

            continue;
        }
        
        
        id model = [self rangeRedTabIcyDict:element];
        
        
        if (model) {
            [frontArray addObject:model];
        }
    }
    
    return [frontArray copy];
}

- (NSMutableDictionary *)hueNotBecomeDict {
    NSMutableDictionary *hall = [NSMutableDictionary dictionary];
    
    
    NSArray *fitBlendBurst = [[self class] variationMinSexAmericanHint];
    NSDictionary *eggSchemes = [[self class] lockingDropBriefTamilFusionSlopeName];
    NSDictionary *ninePinRoman = [[self class] advertiseActionLayoutPhaseGopherArray];
    
    for (NSString *propertyName in fitBlendBurst) {
        NSString *keyPath = eggSchemes[propertyName] ?: propertyName;
        id value = [self valueForKey:propertyName];
        
        if (!value || [value isKindOfClass:[NSNull class]]) continue;
        
        
        if ([value isKindOfClass:[NSObject class]] &&
            ![value isKindOfClass:[NSString class]] &&
            ![value isKindOfClass:[NSNumber class]] &&
            ![value isKindOfClass:[NSArray class]] &&
            ![value isKindOfClass:[NSDictionary class]]) {
            
            value = [value hueNotBecomeDict];
        }
        
        
        if ([value isKindOfClass:[NSArray class]]) {
            NSMutableArray *fingerHasArray = [NSMutableArray array];
            
            
            Class caretOffSort = ninePinRoman[propertyName];
            if (!caretOffSort) {
                
                NSString *className = [[self class] advertiseActionLayoutPhaseGopherArray][propertyName];
                caretOffSort = NSClassFromString(className);
            }
            
            for (id item in value) {
                if (caretOffSort && [item isKindOfClass:caretOffSort]) {
                    
                    [fingerHasArray addObject:[item hueNotBecomeDict]];
                } else if ([item isKindOfClass:[NSObject class]] &&
                          ![item isKindOfClass:[NSString class]] &&
                          ![item isKindOfClass:[NSNumber class]]) {
                    
                    [fingerHasArray addObject:[item hueNotBecomeDict]];
                } else {
                    [fingerHasArray addObject:item];
                }
            }
            value = [fingerHasArray copy];
        }
        
        
        if ([keyPath containsString:@"."]) {
            NSArray *keys = [keyPath componentsSeparatedByString:@"."];
            __block NSMutableDictionary *needBadDict = hall;
            
            [keys enumerateObjectsUsingBlock:^(NSString *key, NSUInteger idx, BOOL *stop) {
                if (idx == keys.count - 1) {
                    needBadDict[key] = value;
                } else {
                    if (!needBadDict[key] || ![needBadDict[key] isKindOfClass:[NSMutableDictionary class]]) {
                        needBadDict[key] = [NSMutableDictionary dictionary];
                    }
                    needBadDict = needBadDict[key];
                }
            }];
        } else {
            hall[keyPath] = value;
        }
    }
    
    return [hall mutableCopy];
}



+ (NSArray<NSString *> *)variationMinSexAmericanHint {
    NSMutableArray *sugar = [NSMutableArray array];
    Class cls = self;
    
    
    while (cls != [NSObject class]) {
        unsigned int count;
        objc_property_t *properties = class_copyPropertyList(cls, &count);
        
        for (unsigned int i = 0; i < count; i++) {
            objc_property_t property = properties[i];
            const char *name = property_getName(property);
            NSString *propertyName = [NSString stringWithUTF8String:name];
            
            
            if (![sugar containsObject:propertyName]) {
                [sugar addObject:propertyName];
            }
        }
        free(properties);
        
        
        cls = [cls superclass];
    }
    return [sugar copy];
}


+ (id)focusFourSexValue:(id)value
       seeHashUndoName:(NSString *)propertyName
              keyPath:(NSString *)keyPath
        mainRateType:(NSString *)mainRateType
       ninePinRoman:(NSDictionary *)ninePinRoman
        oneJobDict:(NSDictionary *)oneJobDict {
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        
        Class jumpDegree = NSClassFromString(mainRateType);

        
        
        BOOL bitChatChest = jumpDegree &&
                           ![jumpDegree isSubclassOfClass:[NSDictionary class]] &&
                           ![jumpDegree isSubclassOfClass:[NSArray class]] &&
                           [jumpDegree respondsToSelector:@selector(rangeRedTabIcyDict:)];
        
        if (!bitChatChest) {

            return value; 
        }
        
        

        id convertedModel = [jumpDegree rangeRedTabIcyDict:value];
        
        
        if (!convertedModel) {

        }
        return convertedModel;
    }
    
    
    if ([value isKindOfClass:[NSArray class]]) {
        Class linerSoft = NSClassFromString(ninePinRoman[propertyName]);
        if (linerSoft) {
            NSMutableArray *sixDid = [NSMutableArray array];
            for (id subValue in value) {
                if ([subValue isKindOfClass:[NSDictionary class]]) {
                    [sixDid addObject:[linerSoft rangeRedTabIcyDict:subValue]];
                } else {
                    [sixDid addObject:subValue];
                }
            }
            return sixDid;
        }
    }
    
    
    if ([keyPath containsString:@"."] && [value isKindOfClass:[NSString class]]) {
        return [self muteNineteenLoadAdvisoryHealthMiterValue:value mainRateType:mainRateType];
    }
    
    return [self muteNineteenLoadAdvisoryHealthMiterValue:value mainRateType:mainRateType];
}


+ (id)muteNineteenLoadAdvisoryHealthMiterValue:(id)value mainRateType:(NSString *)type {
    if ([value isKindOfClass:[NSString class]]) {
        NSString *stringValue = (NSString *)value;
        
        if ([type isEqualToString:@"NSString"]) {
            return stringValue;
        }
        if ([type isEqualToString:@"BOOL"]) {
            return @([stringValue boolValue] ||
                    [stringValue.lowercaseString isEqualToString:@"yes"] ||
                    [stringValue.lowercaseString isEqualToString:@"true"]);
        }
        if ([type isEqualToString:@"NSInteger"]) {
            return @([stringValue integerValue]);
        }
        if ([type isEqualToString:@"int"]) {
            return @([stringValue intValue]);
        }
        if ([type isEqualToString:@"double"]) {
            return @([stringValue doubleValue]);
        }
        if ([type isEqualToString:@"float"]) {
            return @([stringValue floatValue]);
        }
        if ([type isEqualToString:@"NSNumber"]) {
            return [[NSNumberFormatter new] numberFromString:stringValue] ?: @0;
        }
    }
    
    
    if ([value isKindOfClass:[NSNumber class]]) {
        if ([type isEqualToString:@"NSString"]) {
            return [value stringValue];
        }
    }
    
    return value;
}


+ (NSString *)logCookieAssistantRearrangeListenerPipeName:(NSString *)name {
    objc_property_t property = class_getProperty(self, name.UTF8String);
    if (!property) return nil;
    
    const char *attrs = property_getAttributes(property);
    NSString *determineBut = [NSString stringWithUTF8String:attrs];
    
    
    if ([determineBut containsString:@"@\""]) {
        NSRange range = [determineBut rangeOfString:@"@\""];
        NSString *linkMix = [determineBut substringFromIndex:range.location+2];
        linkMix = [linkMix componentsSeparatedByString:@"\""].firstObject;
        return linkMix;
    }
    
    
    const char overCode = attrs[1];
    switch (overCode) {
        case 'B': return @"BOOL";
        case 'q': return @"NSInteger";
        case 'i': return @"int";
        case 'd': return @"double";
        case 'f': return @"float";
        default: return nil;
    }
}


+ (NSDictionary *)lockingDropBriefTamilFusionSlopeName {
    return @{};
}


+ (NSDictionary *)advertiseActionLayoutPhaseGopherArray {
    return @{};
}


- (void)setValue:(id)value forUndefinedKey:(NSString *)key {}

@end
