//
//  CpuMapManager.swift
//  Pods
//
//  Created by 100Years on 2025/6/10.
//

import UIKit

public class CpuMapManager: NSObject {
    static let shared = CpuMapManager()
}

extension UIDevice {
    
    var modelIdentifier: String {
        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)))
        }
        
        return identifier
    }
    
    /// 数据来源 https://www.jianshu.com/p/d9068fee295e
    public var modelName: String {
        
        let identifier = modelIdentifier
        
        switch identifier {
        case "iPhone8,1":
            return "iPhone 6s"
        case "iPhone8,2":
            return "iPhone 6s Plus"
        case "iPhone8,4":
            return "iPhone SE"
        case "iPhone9,1":
            return "iPhone 7"; //国行、日版、港行
        case "iPhone9,2":
            return "iPhone 7 Plus"; //国行、港行
        case "iPhone9,3":
            return "iPhone 7"; //美版、台版
        case "iPhone9,4":
            return "iPhone 7 Plus"; //美版、台版
        case "iPhone10,1":
            return "iPhone 8"; //国行(A1863)、日行(A1906)
        case "iPhone10,2":
            return "iPhone 8 Plus"; //国行(A1864)、日行(A1898)
        case "iPhone10,3":
            return "iPhone X"; //国行(A1865)、日行(A1902)
        case "iPhone10,4":
            return "iPhone 8"; //美版(Global/A1905)
        case "iPhone10,5":
            return "iPhone 8 Plus"; //美版(Global/A1897)
        case "iPhone10,6":
            return "iPhone X";//美版(Global/A1901)
            
        // 刘海屏(除SE外)
        case "iPhone11,8":
            return "iPhone XR"
        case "iPhone11,2":
            return "iPhone XS"
        case "iPhone11,6":
            return "iPhone XS Max"
        case "iPhone11,4":
            return "iPhone XS Max"
        case "iPhone12,1":
            return "iPhone 11"
        case "iPhone12,3":
            return "iPhone 11 Pro"
        case "iPhone12,5":
            return "iPhone 11 Pro Max"
        case "iPhone12,8":
            return "iPhone SE2"; //(2nd generation)
        case "iPhone13,1":
            return "iPhone 12 mini"
        case "iPhone13,2":
            return "iPhone 12"
        case "iPhone13,3":
            return "iPhone 12 Pro"
        case "iPhone13,4":
            return "iPhone 12 Pro Max"
        case "iPhone14,2":
            return "iPhone 13 Pro"
        case "iPhone14,3":
            return "iPhone 13 Pro Max"
        case "iPhone14,4":
            return "iPhone 13 mini"
        case "iPhone14,5":
            return "iPhone 13"
        case "iPhone14,6":
            return "iPhone SE3"; //(2nd generation)
        case "iPhone14,7":
            return "iPhone 14"
        case "iPhone14,8":
            return "iPhone 14 Plus"
            
        // 灵动岛
        case "iPhone15,2":
            return "iPhone 14 Pro"
        case "iPhone15,3":
            return "iPhone 14 Pro Max"
            
        case "iPhone16,2":
            return "iPhone 15 Pro Max"
        case "iPhone16,1":
            return "iPhone 15 Pro"
        case "iPhone15,5":
            return "iPhone 15 Plus"
        case "iPhone15,4":
            return "iPhone 15"

            
        case "iPhone17,3":
            return "iPhone 16"
        case "iPhone17,4":
            return "iPhone 16 Plus"
        case "iPhone17,1":
            return "iPhone 16 Pro"
        case "iPhone17,2":
            return "iPhone 16 Pro Max"
            
            
            
        default:
            return "--"
        }
    }
}
