import 'dart:convert';

// 将 JSON 字符串转换为 VehicleInfo 对象的辅助函数
VehicleInfo vehicleInfoFromJson(String str) => VehicleInfo.fromJson(json.decode(str));

// 将 VehicleInfo 对象转换为 JSON 字符串的辅助函数
String vehicleInfoToJson(VehicleInfo data) => json.encode(data.toJson());

/// 车辆信息数据模型
class VehicleInfo {
    final String plateNumber;
    final String vin;
    final String modelName;
    final String brandName;
    final String engineNum;
    final String truckNum;
    final num hydrogenCapacity;
    final String maxHydrogen;

    VehicleInfo({
        required this.plateNumber,
        required this.vin,
        required this.modelName,
        required this.brandName,
        required this.engineNum,
        required this.truckNum,
        required this.hydrogenCapacity,
        required this.maxHydrogen,
    });

    factory VehicleInfo.fromJson(Map<String, dynamic> json) => VehicleInfo(
        plateNumber: json["plateNumber"] ?? '',
        vin: json["vin"] ?? '',
        modelName: json["modelName"] ?? '',
        brandName: json["brandName"] ?? '',
        engineNum: json["engineNum"] ?? '',
        truckNum: json["truckNum"] ?? '',
        hydrogenCapacity: json["hydrogenCapacity"] ?? 0,
        maxHydrogen: json["maxHydrogen"] ?? '',
    );

    Map<String, dynamic> toJson() => {
        "plateNumber": plateNumber,
        "vin": vin,
        "modelName": modelName,
        "brandName": brandName,
        "engineNum": engineNum,
        "truckNum": truckNum,
        "hydrogenCapacity": hydrogenCapacity,
        "maxHydrogen": maxHydrogen,
    };
}
