//
//  getIphone.swift
//  playbtest
//
//  Created by 忆海16 on 2024/12/31.
//

import Foundation
import UIKit

class getIpne {
    static var shard = getIpne()
    private init() {}

    func getIPhoneModel() -> iPhoneModel {
        var systemInfo = utsname()
        uname(&systemInfo)

        let machineMirror = Mirror(reflecting: systemInfo.machine)
        let identifier = machineMirror.children.reduce("") { identifier, element in
            guard let value = element.value as? Int8, value != 0 else { return identifier }
            return identifier + String(UnicodeScalar(UInt8(value)))
        }

        switch identifier {
        case "iPhone5,1", "iPhone5,2": return .iPhone5
        case "iPhone5,3", "iPhone5,4": return .iPhone5C
        case "iPhone6,1", "iPhone6,2": return .iPhone5S
        case "iPhone7.2": return .iPhone6
        case "iPhone7,1": return .iPhone6Plus
        case "iPhone8,1": return .iPhone6s
        case "iPhone8,2": return .iPhone6Plus
        case "iPhone8,4": return .iPhoneSE1
        case "iPhone9,1", "iPhone9,3": return .iPhone7
        case "iPhone9,2", "iPhone9,4": return .iPhone7Plus
        case "iPhone10,1", "iPhone10,4": return .iPhone8
        case "iPhone10,2", "iPhone10,5": return .iPhone8Plus
        case "iPhone10,3", "iPhone10,6": return .iPhoneX
        case "iPhone11,8": return .iPhoneXR
        case "iPhone11,2": return .iPhoneXS
        case "iPhone11,6", "iPhone11,4": return .iPhoneXSMax
        case "iPhone12,1": return .iPhone11
        case "iPhone12,3": return .iPhone11Pro
        case "iPhone12,5": return .iPhone11ProMax
        case "iPhone12,8": return .iPhoneSE2
        case "iPhone13,1": return .iPhone12Mini
        case "iPhone13,2": return .iPhone12
        case "iPhone13,3": return .iPhone12Pro
        case "iPhone13,4": return .iPhone12ProMax
        case "iPhone14,4": return .iPhone13Mini
        case "iPhone14,5": return .iPhone13
        case "iPhone14,2": return .iPhone13Pro
        case "iPhone14,3": return .iPhone13ProMax
        case "iPhone14,6": return .iPhoneSE3
        case "iPhone14,7": return .iPhone14
        case "iPhone14,8": return .iPhone14Plus
        case "iPhone15,2": return .iPhone14Pro
        case "iPhone15,3": return .iPhone14ProMax
        case "iPhone15,4": return .iPhone15
        case "iPhone15,5": return .iPhone15Plus
        case "iPhone16,1": return .iPhone15Pro
        case "iPhone16,2": return .iPhone15ProMax
        case "i386": return .simulator
        case "x86_64": return .simulator
        default: return .unknown
        }
    }

    public enum iPhoneModel {
        case iPhone15
        case iPhone15Plus
        case iPhone15Pro
        case iPhone15ProMax
        case iPhone14
        case iPhone14Plus
        case iPhone14Pro
        case iPhone14ProMax
        case iPhone13ProMax
        case iPhone13Pro
        case iPhone13
        case iPhone13Mini
        case iPhone12ProMax
        case iPhone12Pro
        case iPhone12
        case iPhone12Mini
        case iPhone11ProMax
        case iPhone11Pro
        case iPhone11
        case iPhoneXSMax
        case iPhoneXS
        case iPhoneXR
        case iPhoneX
        case iPhone8Plus
        case iPhone8
        case iPhone7Plus
        case iPhone7
        case iPhone6sPlus
        case iPhone6s
        case iPhone6Plus
        case iPhone6
        case iPhone5S
        case iPhone5C
        case iPhone5
        case iPhoneSE3
        case iPhoneSE2
        case iPhoneSE1
        case simulator
        case unknown

        public func getName() -> String {
            switch self {
            case .iPhone5: return "iPhone 5"
            case .iPhone5C: return "iPhone 5C"
            case .iPhone5S: return "iPhone 5S"
            case .iPhone6: return "iPhone 6"
            case .iPhone6Plus: return "iPhone 6 Plus"
            case .iPhone6s: return "iPhone 6s"
            case .iPhone6sPlus: return "iPhone 6s Plus"
            case .iPhoneSE1: return "iPhone SE1"
            case .iPhone7: return "iPhone 7"
            case .iPhone7Plus: return "iPhone 7 Plus"
            case .iPhone8: return "iPhone 8"
            case .iPhone8Plus: return "iPhone 8 Plus"
            case .iPhoneX: return "iPhone X"
            case .iPhoneXR: return "iPhone XR"
            case .iPhoneXS: return "iPhone XS"
            case .iPhoneXSMax: return "iPhone XS Max"
            case .iPhone11: return "iPhone 11"
            case .iPhone11Pro: return "iPhone 11 Pro"
            case .iPhone11ProMax: return "iPhone 11 Pro Max"
            case .iPhoneSE2: return "iPhone SE2"
            case .iPhone12Mini: return "iPhone 12 mini"
            case .iPhone12: return "iPhone 12"
            case .iPhone12Pro: return "iPhone 12 Pro"
            case .iPhone12ProMax: return "iPhone 12 Pro Max"
            case .iPhone13Mini: return "iPhone 13 mini"
            case .iPhone13: return "iPhone 13"
            case .iPhone13Pro: return "iPhone 13 Pro"
            case .iPhone13ProMax: return "iPhone 13 Pro Max"
            case .simulator: return "Simulator"
            case .unknown: return "unknown"
            case .iPhone14: return "iPhone 14"
            case .iPhone14Plus: return "iPhone 14 Plus"
            case .iPhone14Pro: return "iPhone 14 Pro"
            case .iPhone14ProMax: return "iPhone 14 Pro Max"
            case .iPhoneSE3: return "iPhone SE3"
            case .iPhone15: return "iPhone 15"
            case .iPhone15Plus: return "iPhone 15 Plus"
            case .iPhone15Pro: return "iPhone 15 Pro"
            case .iPhone15ProMax: return "iPhone 15 Pro Max"
            }
        }
    }
}
