//
//  VFYDeviceTypes.m
//  Verif-y Neo
//
//  Created by MTN on 11/01/21.
//

#import "VFYDeviceTypes.h"
#import <sys/utsname.h>

@implementation VFYDeviceTypes

/*
 * Retrieves back the device name or if not the machine name.
 */
+ (NSString*)deviceModelName {
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *machineName = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    
    NSDictionary *commonNamesDictionary =
    @{
      @"i386":     @"i386 Simulator",
      @"x86_64":   @"x86_64 Simulator",
      
      @"iPhone1,1":    @"iPhone",
      @"iPhone1,2":    @"iPhone 3G",
      @"iPhone2,1":    @"iPhone 3GS",
      @"iPhone3,1":    @"iPhone 4",
      @"iPhone3,2":    @"iPhone 4(Rev A)",
      @"iPhone3,3":    @"iPhone 4(CDMA)",
      @"iPhone4,1":    @"iPhone 4S",
      @"iPhone5,1":    @"iPhone 5(GSM)",
      @"iPhone5,2":    @"iPhone 5(GSM+CDMA)",
      @"iPhone5,3":    @"iPhone 5c(GSM)",
      @"iPhone5,4":    @"iPhone 5c(GSM+CDMA)",
      @"iPhone6,1":    @"iPhone 5s(GSM)",
      @"iPhone6,2":    @"iPhone 5s(GSM+CDMA)",
      
      @"iPhone7,1":    @"iPhone 6+(GSM+CDMA)",
      @"iPhone7,2":    @"iPhone 6(GSM+CDMA)",
      
      @"iPhone8,1":    @"iPhone 6S(GSM+CDMA)",
      @"iPhone8,2":    @"iPhone 6S+(GSM+CDMA)",
      @"iPhone8,4":    @"iPhone SE(GSM+CDMA)",
      @"iPhone9,1":    @"iPhone 7(GSM+CDMA)",
      @"iPhone9,2":    @"iPhone 7+(GSM+CDMA)",
      @"iPhone9,3":    @"iPhone 7(GSM+CDMA)",
      @"iPhone9,4":    @"iPhone 7+(GSM+CDMA)",
      @"iPhone10,1":   @"iPhone 8(CDMA)",
      @"iPhone10,4":   @"iPhone 8(GSM)",
      @"iPhone10,2":   @"iPhone 8+(CDMA)",
      @"iPhone10,5":   @"iPhone 8+(GSM)",
      @"iPhone10,3":   @"iPhone X(CDMA)",
      @"iPhone10,6":   @"iPhone X(GSM)",
      @"iPhone11,2":   @"iPhone XS",
      @"iPhone11,4":   @"iPhone XS Max",
      @"iPhone11,6":   @"iPhone XS Max",
      @"iPhone11,8":   @"iPhone XR",
      @"iPhone12,1":   @"iPhone 11",
      @"iPhone12,3":   @"iPhone 11 Pro",
      @"iPhone12,5":   @"iPhone 11 Pro Max",
      @"iPhone12,8":   @"iPhone SE (2nd generation)",
      @"iPhone13,1":   @"iPhone 12 mini",
      @"iPhone13,2":   @"iPhone 12",
      @"iPhone13,3":   @"iPhone 12 Pro",
      @"iPhone13,4":   @"iPhone 12 Pro Max",
      
      
      @"iPad1,1":  @"iPad",
      @"iPad2,1":  @"iPad 2(WiFi)",
      @"iPad2,2":  @"iPad 2(GSM)",
      @"iPad2,3":  @"iPad 2(CDMA)",
      @"iPad2,4":  @"iPad 2(WiFi Rev A)",
      @"iPad2,5":  @"iPad Mini 1G (WiFi)",
      @"iPad2,6":  @"iPad Mini 1G (GSM)",
      @"iPad2,7":  @"iPad Mini 1G (GSM+CDMA)",
      @"iPad3,1":  @"iPad 3(WiFi)",
      @"iPad3,2":  @"iPad 3(GSM+CDMA)",
      @"iPad3,3":  @"iPad 3(GSM)",
      @"iPad3,4":  @"iPad 4(WiFi)",
      @"iPad3,5":  @"iPad 4(GSM)",
      @"iPad3,6":  @"iPad 4(GSM+CDMA)",
      
      @"iPad4,1":  @"iPad Air(WiFi)",
      @"iPad4,2":  @"iPad Air(GSM)",
      @"iPad4,3":  @"iPad Air(GSM+CDMA)",
      
      @"iPad5,3":  @"iPad Air 2 (WiFi)",
      @"iPad5,4":  @"iPad Air 2 (GSM+CDMA)",
      
      @"iPad4,4":  @"iPad Mini 2G (WiFi)",
      @"iPad4,5":  @"iPad Mini 2G (GSM)",
      @"iPad4,6":  @"iPad Mini 2G (GSM+CDMA)",
      
      @"iPad4,7":  @"iPad Mini 3G (WiFi)",
      @"iPad4,8":  @"iPad Mini 3G (GSM)",
      @"iPad4,9":  @"iPad Mini 3G (GSM+CDMA)",
      @"iPad6,11": @"iPad (5th generation)",
      @"iPad6,12": @"iPad (5th generation)",
      @"iPad7,5":  @"iPad (6th generation)",
      @"iPad7,6":  @"iPad (6th generation)",
      @"iPad7,11": @"iPad (7th generation)",
      @"iPad7,12": @"iPad (7th generation)",
      @"iPad11,6": @"iPad (8th generation)",
      @"iPad11,7": @"iPad (8th generation)",
      @"iPad11,3": @"iPad Air (3rd generation)",
      @"iPad11,4": @"iPad Air (3rd generation)",
      @"iPad13,1": @"iPad Air (4th generation)",
      @"iPad13,2": @"iPad Air (4th generation)",
      @"iPad5,1":  @"iPad mini 4",
      @"iPad5,2": @"iPad mini 4",
      @"iPad11,1": @"iPad mini (5th generation)",
      @"iPad11,2": @"iPad mini (5th generation)",
      @"iPad6,3": @"iPad Pro (9.7-inch)",
      @"iPad6,4": @"iPad Pro (9.7-inch)",
      @"iPad7,3": @"iPad Pro (10.5-inch)",
      @"iPad7,4": @"iPad Pro (10.5-inch)",
      @"iPad8,1": @"iPad Pro (11-inch) (1st generation)",
      @"iPad8,2": @"iPad Pro (11-inch) (1st generation)",
      @"iPad8,3": @"iPad Pro (11-inch) (1st generation)",
      @"iPad8,4": @"iPad Pro (11-inch) (1st generation)",
      @"iPad8,9": @"iPad Pro (11-inch) (2nd generation)",
      @"iPad8,10": @"iPad Pro (11-inch) (2nd generation)",
      @"iPad6,7": @"iPad Pro (12.9-inch) (1st generation)",
      @"iPad6,8": @"iPad Pro (12.9-inch) (1st generation)",
      @"iPad7,1": @"iPad Pro (12.9-inch) (2nd generation)",
      @"iPad7,2": @"iPad Pro (12.9-inch) (2nd generation)",
      @"iPad8,5": @"iPad Pro (12.9-inch) (3rd generation)",
      @"iPad8,6": @"iPad Pro (12.9-inch) (3rd generation)",
      @"iPad8,7": @"iPad Pro (12.9-inch) (3rd generation)",
      @"iPad8,8": @"iPad Pro (12.9-inch) (3rd generation)",
      @"iPad8,12": @"iPad Pro (12.9-inch) (4th generation)",
      @"iPad8,12": @"iPad Pro (12.9-inch) (4th generation)",
      
      @"iPod1,1":  @"iPod 1st Gen",
      @"iPod2,1":  @"iPod 2nd Gen",
      @"iPod3,1":  @"iPod 3rd Gen",
      @"iPod4,1":  @"iPod 4th Gen",
      @"iPod5,1":  @"iPod 5th Gen",
      @"iPod7,1":  @"iPod 6th Gen",
      @"iPod9,1":  @"iPod touch (7th generation)",
      };
    
    NSString *deviceName = commonNamesDictionary[machineName];
    
    if (deviceName == nil) {
        deviceName = machineName;
    }
    
    return deviceName;
}

+ (NSString *)deviceModelOS {
    return [[UIDevice currentDevice] systemVersion];
}

@end
