 import Foundation
 
 // MARK: - Functions
+
+struct Model: Hashable {
+
+    let version: Double
+    let enumCase: String
+
+    func hash(into hasher: inout Hasher) {
+        hasher.combine(enumCase)
+    }
+}
+
+func getUniqueSortedModels(havingPrefix: String, from deviceList: [String: [String: AnyObject]]) -> [Model] {
+
+    let filteredDict = deviceList.filter { $0.key.hasPrefix(havingPrefix) }
+    let models: [Model] = filteredDict.values.compactMap {
+
+        guard let version = $0["version"] as? NSNumber, let enumCase = $0["enum"] as? String else {
+            return nil
+        }
+        return Model(version: version.doubleValue, enumCase: enumCase)
+    }
+
+    // Get the unique models i.e. ignore models which has same enum, we don't want same enum twice in case that
+    // will cause compiler error
+    let modelSet = Set(models)
+    return modelSet.sorted { $0.version < $1.version }
+}
 
 func readPropertyList() -> [String: [String: AnyObject]]? {
     var propertyListFormat =  PropertyListSerialization.PropertyListFormat.xml

    guard let generatorDeviceList = readPropertyList() else { return }
    let tabSpacing = "    "
    let unknownCase = "UNKNOWN"
    var deviceList: [String: [String: AnyObject]] = [:]
    var externString = ""
    var externDefString = ""

    }


    var enumString = "typedef NS_ENUM(NSUInteger, Hardware) {\n\n"

    // Get devices by device type
    let iPhoneModels = getUniqueSortedModels(havingPrefix: "iPhone", from: generatorDeviceList)
    iPhoneModels.forEach {
        enumString += "\n\(tabSpacing)\($0.enumCase),"
    }
    enumString += "\n"

    let iPodModels = getUniqueSortedModels(havingPrefix: "iPod", from: generatorDeviceList)
    iPodModels.forEach {
        enumString += "\n\(tabSpacing)\($0.enumCase),"
    }
    enumString += "\n"

    let iPadModels = getUniqueSortedModels(havingPrefix: "iPad", from: generatorDeviceList)
    iPadModels.forEach {
        enumString += "\n\(tabSpacing)\($0.enumCase),"
    }
    enumString += "\n"

    let watchModels = getUniqueSortedModels(havingPrefix: "Watch", from: generatorDeviceList)
    watchModels.forEach {
        enumString += "\n\(tabSpacing)\($0.enumCase),"
    }
    enumString += "\n"

    let appleTVModels = getUniqueSortedModels(havingPrefix: "AppleTV", from: generatorDeviceList)
    appleTVModels.forEach {
        enumString += "\n\(tabSpacing)\($0.enumCase),"
    }
    enumString += "\n"
    enumString += "\n\(tabSpacing)\(simulateCase),"
    enumString += "\n\(tabSpacing)\(unknownCase)"
    enumString += "\n};"

    let dirPath = "../Source/"
