// models/printer_settings.dart
class PrinterSettings {
  final String? ipAddress;
  final int? port;
  final String? name;
  final String? type;
  final int? id;
  final DateTime? createdAt;
  final DateTime? updatedAt;

  PrinterSettings({
    this.ipAddress,
    this.port,
    this.name,
    this.type,
    this.id,
    this.createdAt,
    this.updatedAt,
  });

  factory PrinterSettings.fromJson(Map<String, dynamic> json) {
    return PrinterSettings(
      ipAddress: json['ip_address'],
      port: json['port'] ?? 9100,
      name: json['name'],
      type: json['type'],
      id: json['id'],
      createdAt: json['created_at'] != null ? DateTime.parse(json['created_at']) : null,
      updatedAt: json['updated_at'] != null ? DateTime.parse(json['updated_at']) : null,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'ip_address': ipAddress,
      'port': port,
      'name': name,
      'type': type,
      'id': id,
      'created_at': createdAt?.toIso8601String(),
      'updated_at': updatedAt?.toIso8601String(),
    };
  }

  // Méthode pour créer un objet de test de connexion
  Map<String, dynamic> toTestJson() {
    return {
      'ip_address': ipAddress,
      'port': port,
    };
  }
}