//
//  SiiPrinter.m
//

#import "SiiPrinter.h"
#import "SampleValue.h"

@implementation SiiPrinter

@synthesize type;
@synthesize model;
@synthesize address;
@synthesize modelName;
@synthesize portType;
@synthesize seriesName;

- (instancetype)init {
    self.type = -1;
    self.model = -1;
    self.address = @"";
    self.modelName = @"";
    self.portType = @"";
    self.seriesName = @"";
    return self;
}

/// Set a printer instance from given address, modelName and portType
- (instancetype)initWithPrinterInformation:(NSString *)address modelName:(NSString *)modelName portType:(NSString *)portType {
    self.address = address;
    self.modelName = modelName;
    self.portType = portType;
    self.model = [self getPrinterModel: modelName];
    self.type = [self getPrinterType: portType];
    return self;
}

/// Get printer's model name from series name
/// - Parameter seriesName: printer series name
/// - Returns: printer model name
- (NSString *)getPrinterModelName:(NSString *)seriesName {
    if ([seriesName rangeOfString:PRINTER_SERIES_NAME_RPE10].location != NSNotFound) {
        return PRINTER_MODEL_NAME_RPE10;
    } else if ([seriesName rangeOfString:PRINTER_SERIES_NAME_RPD10].location != NSNotFound) {
        return PRINTER_MODEL_NAME_RPD10;
    } else if ([seriesName rangeOfString:PRINTER_SERIES_NAME_RPF10].location != NSNotFound) {
        return PRINTER_MODEL_NAME_RPF10;
    } else if ([seriesName rangeOfString:PRINTER_SERIES_NAME_DPUS].location != NSNotFound) {
        return PRINTER_MODEL_NAME_DPUS245;
    } else if ([seriesName rangeOfString:PRINTER_SERIES_NAME_MPB20].location != NSNotFound) {
        return PRINTER_MODEL_NAME_MPB20;
    } else if ([seriesName rangeOfString:PRINTER_SERIES_NAME_MPB21L].location != NSNotFound) {
        return PRINTER_MODEL_NAME_MPB21L;
    } else if ([seriesName rangeOfString:PRINTER_SERIES_NAME_MPB30L].location != NSNotFound) {
        return PRINTER_MODEL_NAME_MPB30L;
    } else if ([seriesName rangeOfString:PRINTER_SERIES_NAME_MPB30].location != NSNotFound) {
        return PRINTER_MODEL_NAME_MPB30;
    } else if ([seriesName rangeOfString:PRINTER_SERIES_NAME_SLP72].location != NSNotFound) {
        return PRINTER_MODEL_NAME_SLP720RT;
    } else if ([seriesName rangeOfString:PRINTER_SERIES_NAME_MPA40].location != NSNotFound) {
        return PRINTER_MODEL_NAME_MPA40;
    } else {
        return PRINTER_MODEL_NAME_UNKNOWN;
    }
}

/// Get printer's model number from model name
/// - Parameter modelName: printer model name
/// - Returns: printer model number
- (NSInteger)getPrinterModel:(NSString *)modelName {
    if ([modelName rangeOfString:PRINTER_MODEL_NAME_RPE10].location != NSNotFound) {
        return SII_PM_PRINTER_MODEL_RP_E10;
    } else if ([modelName rangeOfString:PRINTER_MODEL_NAME_RPD10].location != NSNotFound) {
        return SII_PM_PRINTER_MODEL_RP_D10;
    } else if ([modelName rangeOfString:PRINTER_MODEL_NAME_RPF10].location != NSNotFound) {
        return SII_PM_PRINTER_MODEL_RP_F10;
    } else if ([modelName rangeOfString:PRINTER_MODEL_NAME_DPUS245].location != NSNotFound) {
        return SII_PM_PRINTER_MODEL_DPU_S245;
    } else if ([modelName rangeOfString:PRINTER_MODEL_NAME_DPUS445].location != NSNotFound) {
        return SII_PM_PRINTER_MODEL_DPU_S445;
    } else if ([modelName rangeOfString:PRINTER_MODEL_NAME_MPB20].location != NSNotFound) {
        return SII_PM_PRINTER_MODEL_MP_B20;
    } else if ([modelName rangeOfString:PRINTER_MODEL_NAME_MPB21L].location != NSNotFound) {
        return SII_PM_PRINTER_MODEL_MP_B21L;
    } else if ([modelName rangeOfString:PRINTER_MODEL_NAME_MPB30L].location != NSNotFound) {
        return SII_PM_PRINTER_MODEL_MP_B30L;
    } else if ([modelName rangeOfString:PRINTER_MODEL_NAME_MPB30].location != NSNotFound) {
        return SII_PM_PRINTER_MODEL_MP_B30;
    } else if ([modelName rangeOfString:PRINTER_MODEL_NAME_SLP720RT].location != NSNotFound) {
        return SII_PM_PRINTER_MODEL_SLP720RT;
    } else if ([modelName rangeOfString:PRINTER_MODEL_NAME_MPA40].location != NSNotFound) {
        return SII_PM_PRINTER_MODEL_MP_A40;
    } else {
        return -1;
    }
}

/// Get printer's port type number from port type name
/// - Parameter type: printer port type number
/// - Returns: printer port type name
- (NSString *)getPrinterPortType:(NSInteger)type {
    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
- (NSInteger)getPrinterType:(NSString *)portType {
    if ([portType rangeOfString: PRINTER_PORT_TYPE_NAME_TCPIP].location != NSNotFound) {
        return SII_PM_PRINTER_PORT_TYPE_TCP;
    } else if ([portType rangeOfString: PRINTER_PORT_TYPE_NAME_BLUETOOTH].location != NSNotFound) {
        return SII_PM_PRINTER_PORT_TYPE_BLUETOOTH;
    } else if ([portType rangeOfString: PRINTER_PORT_TYPE_NAME_USB].location != NSNotFound) {
        return SII_PM_PRINTER_PORT_TYPE_USB;
    } else {
        return -1;
    }
}

@end

