//
//  SiiPrinter.swift
//  SiiLibSample
//

import Foundation

/// A struct defines informatioms for printer
/// 
/// Properties:
///  - model: Printer model number (Int32)
///  - type: Printer port type number (Int32)
///  - address: Printer address (String)
///  - modelName: Printer model name (String)
///  - portType: Printer port type name (String)
///  - seriesName: Printer series name (String)
struct SiiPrinter: Identifiable {
    var id = UUID()
    var model: Int32
    var type: Int32
    var address: String
    var modelName: String
    var portType: String
    var seriesName: String
    
    init() {
        self.model = -1
        self.type = -1
        self.address = ""
        self.modelName = ""
        self.portType = ""
        self.seriesName = ""
    }
    
    /// Get printer's model name from series name
    /// - Parameter seriesName: printer series name
    /// - Returns: printer model name
    func getPrinterModelName(seriesName: String) -> String {
        if seriesName.contains(PRINTER_SERIES_NAME_RPF10) {
            return PRINTER_MODEL_NAME_RPF10
        }
        else if seriesName.contains(PRINTER_SERIES_NAME_RPE10) {
            return PRINTER_MODEL_NAME_RPE10
        }
        else if seriesName.contains(PRINTER_SERIES_NAME_RPD10) {
            return PRINTER_MODEL_NAME_RPD10
        }
        else if seriesName.contains(PRINTER_SERIES_NAME_DPUS) {
            return PRINTER_MODEL_NAME_DPUS245
        }
        else if seriesName.contains(PRINTER_SERIES_NAME_MPB21L) {
            return PRINTER_MODEL_NAME_MPB21L
        }
        else if seriesName.contains(PRINTER_SERIES_NAME_MPB20) {
            return PRINTER_MODEL_NAME_MPB20
        }
        else if seriesName.contains(PRINTER_SERIES_NAME_MPB30L) {
            return PRINTER_MODEL_NAME_MPB30L
        }
        else if seriesName.contains(PRINTER_SERIES_NAME_MPB30) {
            return PRINTER_MODEL_NAME_MPB30
        }
        else if seriesName.contains(PRINTER_SERIES_NAME_SLP72) {
            return PRINTER_MODEL_NAME_SLP720RT
        }
        else if seriesName.contains(PRINTER_SERIES_NAME_MPA40) {
            return PRINTER_MODEL_NAME_MPA40
        }
        return PRINTER_MODEL_NAME_UNKNOWN
    }
    
    /// Get printer's model number from model name
    /// - Parameter modelName: printer model name
    /// - Returns: printer model number
    func getPrinterModel(modelName: String) -> Int32 {
        if modelName.contains(PRINTER_MODEL_NAME_RPF10) {
            return SII_PM_PRINTER_MODEL_RP_F10
        }
        else if modelName.contains(PRINTER_MODEL_NAME_RPE10) {
            return SII_PM_PRINTER_MODEL_RP_E10
        }
        else if modelName.contains(PRINTER_MODEL_NAME_RPD10) {
            return SII_PM_PRINTER_MODEL_RP_D10
        }
        else if modelName.contains(PRINTER_MODEL_NAME_DPUS245) {
            return SII_PM_PRINTER_MODEL_DPU_S245
        }
        else if modelName.contains(PRINTER_MODEL_NAME_DPUS445) {
            return SII_PM_PRINTER_MODEL_DPU_S445
        }
        else if modelName.contains(PRINTER_MODEL_NAME_MPB21L) {
            return SII_PM_PRINTER_MODEL_MP_B21L
        }
        else if modelName.contains(PRINTER_MODEL_NAME_MPB20) {
            return SII_PM_PRINTER_MODEL_MP_B20
        }
        else if modelName.contains(PRINTER_MODEL_NAME_MPB30L) {
            return SII_PM_PRINTER_MODEL_MP_B30L
        }
        else if modelName.contains(PRINTER_MODEL_NAME_MPB30) {
            return SII_PM_PRINTER_MODEL_MP_B30
        }
        else if modelName.contains(PRINTER_MODEL_NAME_SLP720RT) {
            return SII_PM_PRINTER_MODEL_SLP720RT
        }
        else if modelName.contains(PRINTER_MODEL_NAME_MPA40) {
            return SII_PM_PRINTER_MODEL_MP_A40
        }
        return -1
    }
    
    /// Get printer's port type number from port type name
    /// - Parameter type: printer port type number
    /// - Returns: printer port type name
    func getPrinterPortType(type: Int32) -> String {
        if type == SII_PM_PRINTER_PORT_TYPE_TCP {
            return PRINTER_PORT_TYPE_NAME_TCPIP
        }
        else if type == SII_PM_PRINTER_PORT_TYPE_BLUETOOTH {
            return PRINTER_PORT_TYPE_NAME_BLUETOOTH
        }
        else if type == SII_PM_PRINTER_PORT_TYPE_USB {
            return PRINTER_PORT_TYPE_NAME_USB
        }
        else {
            return PRINTER_PORT_TYPE_NAME_OTHER
        }
    }
    
    /// Get printer's port type name from port type number
    /// - Parameter portType: printer port type name
    /// - Returns: printer port type number
    func getPrinterType(portType: String) -> Int32 {
        if portType == PRINTER_PORT_TYPE_NAME_TCPIP {
            return SII_PM_PRINTER_PORT_TYPE_TCP
        }
        else if portType == PRINTER_PORT_TYPE_NAME_BLUETOOTH {
            return SII_PM_PRINTER_PORT_TYPE_BLUETOOTH
        }
        else if portType == PRINTER_PORT_TYPE_NAME_USB {
            return SII_PM_PRINTER_PORT_TYPE_USB
        }
        else {
            return -1
        }
    }
}
