
import 'package:satu/core/utils/utils_parse.dart';

class PrinterConst {
  PrinterConst();
  static const String paperSize58mm = '58mm';
  static const String paperSize80mm = '80mm';
  static const String encodingCP866 = 'CP866';
  static const String encodingCP1251 = 'Windows-1251';
  static const String encodingBigEncoding = 'BigEncoding';
}

class PrinterSetting {

  factory PrinterSetting.fromMap(dynamic map) {
    return PrinterSetting(
      device: map['device']!=null ? PrinterDevice.fromMap(map['device']) : null,
      encoding: cast<String>(map['encoding']),
      paperSize: cast<String>(map['paperSize']),
    );
  }

  PrinterSetting({
    this.device,
    this.encoding = PrinterConst.encodingCP866,
    this.paperSize = PrinterConst.paperSize58mm,
  });

  PrinterDevice? device;
  String? encoding ;
  String? paperSize ;

  dynamic toMap() {
    return {
      'device': device != null ? device!.toMap() : null,
      'encoding': encoding,
      'paperSize': paperSize,
    };
  }

}

class PrinterDevice {

  factory PrinterDevice.fromMap(dynamic map) {
    return PrinterDevice(
      name: cast<String>(map['name']),
      address: cast<String>(map['address']),
      type: cast<int>(map['type']),
      connected: cast<bool>(map['connected']),
    );
  }

  PrinterDevice({
    this.name,
    this.address,
    this.type,
    this.connected,
  });
  String? name;
  String? address;
  int? type = 0;
  bool? connected = false;

  dynamic toMap() {
    return {
      'name': name,
      'address': address,
      'type': type,
      'connected': connected,
    };
  }
}