class FilamentModel {
  final String documentId;
  final String name;
  final String type;
  final String color;
  final double weight;
  final double weightUsed;
  final double price;
  final String manufacturer;
  final String purchaseDate;
  final String? notes;
  final int printingTemp;
  final int bedTemp;

  FilamentModel({
    required this.documentId,
    required this.name,
    required this.type,
    required this.color,
    required this.weight,
    required this.weightUsed,
    required this.price,
    required this.manufacturer,
    required this.purchaseDate,
    this.notes,
    required this.printingTemp,
    required this.bedTemp,
  });

  static FilamentModel fromJson(Map<String, dynamic> json) {
    return FilamentModel(
      documentId: json['\$id'] as String? ?? '',
      name: json['name'] as String? ?? '',
      type: json['type'] as String? ?? '',
      color: json['color'] as String? ?? '',
      weight: (json['weight'] as num?)?.toDouble() ?? 0.0,
      weightUsed: (json['weightUsed'] as num?)?.toDouble() ?? 0.0,
      price: (json['price'] as num?)?.toDouble() ?? 0.0,
      manufacturer: json['manufacturer'] as String? ?? '',
      purchaseDate: json['purchaseDate'] as String? ?? '',
      notes: json['notes'] as String?,
      printingTemp: (json['printingTemp'] as num?)?.toInt() ?? 0,
      bedTemp: (json['bedTemp'] as num?)?.toInt() ?? 0,
    );
  }

  static Map<String, dynamic> toMapForAppwrite(FilamentModel filamentModel) {
    return {
      'name': filamentModel.name,
      'type': filamentModel.type,
      'color': filamentModel.color,
      'weight': filamentModel.weight,
      'weightUsed': filamentModel.weightUsed,
      'price': filamentModel.price,
      'manufacturer': filamentModel.manufacturer,
      'purchaseDate': filamentModel.purchaseDate,
      if (filamentModel.notes != null) 'notes': filamentModel.notes,
      'printingTemp': filamentModel.printingTemp,
      'bedTemp': filamentModel.bedTemp,
    };
  }

  // An empty instance for initialization or default values
  static final empty = FilamentModel(
    documentId: '00',
    name: '',
    type: '',
    color: '',
    weight: 0.0,
    weightUsed: 0.0,
    price: 0.0,
    manufacturer: '',
    purchaseDate: '',
    notes: null,
    printingTemp: 0,
    bedTemp: 0,
  );
}
