class AppWriteTankModel {
  String documentId;
  String userId;
  String date;
  String odometer;
  String liters;
  String pricePerLiter;
  String location;
  String? imageFileId;
  String? imageFileName;
  String? imageFileUrl;
  int? mnIndexCount;
  String? szSummePreis;

  AppWriteTankModel({
    required this.documentId,
    required this.userId,
    required this.date,
    required this.odometer,
    required this.liters,
    required this.pricePerLiter,
    required this.location,
    this.imageFileId,
    this.imageFileName,
    this.imageFileUrl,
  }):szSummePreis = (double.tryParse(liters) != null && double.tryParse(pricePerLiter) != null)
        ? (double.parse(liters) * double.parse(pricePerLiter)).toStringAsFixed(2)
        : null;

  factory AppWriteTankModel.fromMap(Map<String, dynamic> map) {
    return AppWriteTankModel(
      documentId: map['\$id'] ?? '',
      userId: map['userId'] ?? '',
      date: map['date'] ?? '',
      odometer: map['odometer']?.toString() ?? '',
      liters: map['liters']?.toString() ?? '',
      pricePerLiter: map['pricePerLiter']?.toString() ?? '',
      location: map['location'] ?? '',
      imageFileId: map['imageFileId'],
      imageFileName: map['imageFileName'],
      imageFileUrl: map['imageFileUrl'],
    );
  }
  Map<String, dynamic> toMap() {
    return {
      '\$id': documentId,
      'userId': userId,
      'date': date,
      'odometer': odometer,
      'liters': liters,
      'pricePerLiter': pricePerLiter,
      'location': location,
      'imageFileId': imageFileId,
      'imageFileName': imageFileName,
      'imageFileUrl': imageFileUrl,
    };
  }
}
