import 'dart:io';

import 'package:mc_common_app/utils/utils.dart';

class GenericRespModel {
  GenericRespModel({
    this.data,
    this.messageStatus,
    this.totalItemsCount,
    this.message,
  });

  dynamic data;
  int? messageStatus;
  int? totalItemsCount;
  String? message;

  factory GenericRespModel.fromJson(Map<String, dynamic> json) {
    if (json.containsKey('StatusMessage')) {
      if ((json['StatusMessage'] as String).contains('Internal server error')) {
        Utils.showToast("${json['StatusMessage']}");
      }
    }
    return GenericRespModel(
      data: json["data"],
      messageStatus: json["messageStatus"],
      totalItemsCount: json["totalItemsCount"],
      message: json["message"],
    );
  }

  Map<String, dynamic> toJson() => {
        "data": data,
        "messageStatus": messageStatus,
        "totalItemsCount": totalItemsCount,
        "message": message,
      };
}

class AdsCreationPayloadModel {
  Ads? ads;
  VehiclePosting? vehiclePosting;

  AdsCreationPayloadModel({this.ads, this.vehiclePosting});

  AdsCreationPayloadModel.fromJson(Map<String, dynamic> json) {
    ads = json['ads'] != null ? Ads.fromJson(json['ads']) : null;
    vehiclePosting = json['vehiclePosting'] != null ? VehiclePosting.fromJson(json['vehiclePosting']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    if (ads != null) {
      data['ads'] = ads!.toJson();
    }
    if (vehiclePosting != null) {
      data['vehiclePosting'] = vehiclePosting!.toJson();
    }
    return data;
  }
}

class Ads {
  int? id;
  int? adsDurationID;
  String? startDate;
  int? countryId;
  List<int>? specialServiceIDs;
  bool? isMCHandled;

  Ads({this.id, this.adsDurationID, this.startDate, this.countryId, this.specialServiceIDs, this.isMCHandled});

  Ads.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    adsDurationID = json['adsDurationID'];
    startDate = json['startDate'];
    countryId = json['countryId'];
    specialServiceIDs = json['specialServiceIDs'].cast<int>();
    isMCHandled = json['isMCHandled'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['adsDurationID'] = adsDurationID;
    data['startDate'] = startDate;
    data['countryId'] = countryId;
    data['specialServiceIDs'] = specialServiceIDs;
    data['isMCHandled'] = isMCHandled;
    return data;
  }

  @override
  String toString() {
    return 'Ads{id: $id, adsDurationID: $adsDurationID, startDate: $startDate, countryId: $countryId, specialServiceIDs: $specialServiceIDs, isMCHandled: $isMCHandled}';
  }
}

class VehiclePosting {
  int? id;
  String? userID;
  int? vehicleType;
  int? vehicleModelID;
  int? vehicleModelYearID;
  int? vehicleColorID;
  int? vehicleCategoryID;
  int? vehicleConditionID;
  int? vehicleMileageID;
  int? vehicleTransmissionID;
  int? vehicleSellerTypeID;
  int? cityID;
  int? price;
  String? vehicleVIN;
  String? vehicleDescription;
  String? vehicleTitle;
  String? vehicleDescriptionN;
  bool? isFinanceAvailable;
  int? warantyYears;
  int? demandAmount;
  int? adStatus;
  List<VehiclePostingImages>? vehiclePostingImages;
  List<VehiclePostingDamageParts>? vehiclePostingDamageParts;
  String? phoneNo;
  String? whatsAppNo;

  VehiclePosting(
      {this.id,
      this.userID,
      this.vehicleType,
      this.vehicleModelID,
      this.vehicleModelYearID,
      this.vehicleColorID,
      this.vehicleCategoryID,
      this.vehicleConditionID,
      this.vehicleMileageID,
      this.vehicleTransmissionID,
      this.vehicleSellerTypeID,
      this.cityID,
      this.price,
      this.vehicleVIN,
      this.vehicleDescription,
      this.vehicleTitle,
      this.vehicleDescriptionN,
      this.isFinanceAvailable,
      this.warantyYears,
      this.demandAmount,
      this.adStatus,
      this.phoneNo,
      this.whatsAppNo,
      this.vehiclePostingImages,
      this.vehiclePostingDamageParts});

  VehiclePosting.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    userID = json['userID'];
    vehicleType = json['vehicleType'];
    vehicleModelID = json['vehicleModelID'];
    vehicleModelYearID = json['vehicleModelYearID'];
    vehicleColorID = json['vehicleColorID'];
    vehicleCategoryID = json['vehicleCategoryID'];
    vehicleConditionID = json['vehicleConditionID'];
    vehicleMileageID = json['vehicleMileageID'];
    vehicleTransmissionID = json['vehicleTransmissionID'];
    vehicleSellerTypeID = json['vehicleSellerTypeID'];
    cityID = json['cityID'];
    price = json['price'];
    vehicleVIN = json['vehicleVIN'];
    vehicleDescription = json['vehicleDescription'];
    vehicleTitle = json['vehicleTitle'];
    vehicleDescriptionN = json['vehicleDescriptionN'];
    isFinanceAvailable = json['isFinanceAvailable'];
    warantyYears = json['warantyYears'];
    demandAmount = json['demandAmount'];
    adStatus = json['adStatus'];
    phoneNo = json['phoneNo'];
    whatsAppNo = json['whatsAppNo'];
    if (json['vehiclePostingImages'] != null) {
      vehiclePostingImages = <VehiclePostingImages>[];
      json['vehiclePostingImages'].forEach((v) {
        vehiclePostingImages!.add(VehiclePostingImages.fromJson(v));
      });
    }
    if (json['vehiclePostingDamageParts'] != null) {
      vehiclePostingDamageParts = <VehiclePostingDamageParts>[];
      json['vehiclePostingDamageParts'].forEach((v) {
        vehiclePostingDamageParts!.add(VehiclePostingDamageParts.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['userID'] = userID;
    data['vehicleType'] = vehicleType;
    data['vehicleModelID'] = vehicleModelID;
    data['vehicleModelYearID'] = vehicleModelYearID;
    data['vehicleColorID'] = vehicleColorID;
    data['vehicleCategoryID'] = vehicleCategoryID;
    data['vehicleConditionID'] = vehicleConditionID;
    data['vehicleMileageID'] = vehicleMileageID;
    data['vehicleTransmissionID'] = vehicleTransmissionID;
    data['vehicleSellerTypeID'] = vehicleSellerTypeID;
    data['cityID'] = cityID;
    data['price'] = price;
    data['vehicleVIN'] = vehicleVIN;
    data['vehicleDescription'] = vehicleDescription;
    data['vehicleTitle'] = vehicleTitle;
    data['vehicleDescriptionN'] = vehicleDescriptionN;
    data['isFinanceAvailable'] = isFinanceAvailable;
    data['warantyYears'] = warantyYears;
    data['demandAmount'] = demandAmount;
    data['adStatus'] = adStatus;
    data['phoneNo'] = phoneNo;
    data['whatsAppNo'] = whatsAppNo;
    if (vehiclePostingImages != null) {
      data['vehiclePostingImages'] = vehiclePostingImages!.map((v) => v.toJson()).toList();
    }
    if (vehiclePostingDamageParts != null) {
      data['vehiclePostingDamageParts'] = vehiclePostingDamageParts!.map((v) => v.toJson()).toList();
    }
    return data;
  }

  @override
  String toString() {
    return 'VehiclePosting{id: $id, userID: $userID, vehicleType: $vehicleType, vehicleModelID: $vehicleModelID, vehicleModelYearID: $vehicleModelYearID, vehicleColorID: $vehicleColorID, vehicleCategoryID: $vehicleCategoryID, vehicleConditionID: $vehicleConditionID, vehicleMileageID: $vehicleMileageID, vehicleTransmissionID: $vehicleTransmissionID, vehicleSellerTypeID: $vehicleSellerTypeID, cityID: $cityID, price: $price, vehicleVIN: $vehicleVIN, vehicleDescription: $vehicleDescription, vehicleTitle: $vehicleTitle, vehicleDescriptionN: $vehicleDescriptionN, isFinanceAvailable: $isFinanceAvailable, warantyYears: $warantyYears, demandAmount: $demandAmount, adStatus: $adStatus, vehiclePostingImages: $vehiclePostingImages, vehiclePostingDamageParts: $vehiclePostingDamageParts, phoneNo: $phoneNo, whatsAppNo: $whatsAppNo}';
  }
}

class VehiclePostingImages {
  int? id;
  File? file;
  String? imageName;
  String? imageUrl;
  String? imageStr;
  int? vehiclePostingID;
  String? vehiclePosting;

  VehiclePostingImages({this.id, this.file, this.imageName, this.imageUrl, this.imageStr, this.vehiclePostingID, this.vehiclePosting});

  VehiclePostingImages.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    file = null;
    imageName = json['imageName'];
    imageUrl = json['imageUrl'];
    imageStr = json['imageStr'];
    vehiclePostingID = json['vehiclePostingID'];
    vehiclePosting = json['vehiclePosting'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['imageName'] = imageName;
    data['imageUrl'] = imageUrl;
    data['imageStr'] = imageStr;
    data['vehiclePostingID'] = vehiclePostingID;
    data['vehiclePosting'] = vehiclePosting;
    return data;
  }

  @override
  String toString() {
    return 'VehiclePostingImages{id: $id, imageName: $imageName, imageUrl: $imageUrl, imageStr: "", vehiclePostingID: $vehiclePostingID, vehiclePosting: $vehiclePosting}';
  }
}

class RequestPostingImages {
  int? id;
  String? requestImage;
  int? requestID;

  RequestPostingImages({this.id, this.requestImage, this.requestID});

  RequestPostingImages.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    requestImage = json['requestImage'];
    requestID = json['requestID'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id ?? 0;
    data['requestImage'] = requestImage;
    data['requestID'] = requestID ?? 0;
    return data;
  }

  @override
  String toString() {
    return 'RequestPostingImages{id: $id, requestImage: $requestImage, requestID: $requestID}';
  }
}

class VehiclePostingDamageParts {
  int? id;
  File? file;
  String? comment;
  String? imageUrl;
  String? vehicleImageBase64;
  int? vehicleDamagePartID;
  int? vehiclePostingID;
  bool? isActive;

  VehiclePostingDamageParts({this.id, this.file, this.comment, this.imageUrl, this.vehicleImageBase64, this.vehicleDamagePartID, this.vehiclePostingID, this.isActive});

  VehiclePostingDamageParts.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    file = null;
    comment = json['comment'];
    imageUrl = json['imageUrl'];
    vehicleImageBase64 = json['vehicleImageBase64'];
    vehicleDamagePartID = json['vehicleDamagePartID'];
    vehiclePostingID = json['vehiclePostingID'];
    isActive = json['isActive'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['comment'] = comment;
    data['imageUrl'] = imageUrl;
    data['vehicleImageBase64'] = vehicleImageBase64;
    data['vehicleDamagePartID'] = vehicleDamagePartID;
    data['vehiclePostingID'] = vehiclePostingID;
    data['isActive'] = isActive;
    return data;
  }

  @override
  String toString() {
    return 'VehiclePostingDamageParts{id: $id, comment: $comment, vehicleImageBase64: $vehicleImageBase64, vehicleDamagePartID: $vehicleDamagePartID, vehiclePostingID: $vehiclePostingID, isActive: $isActive}';
  }
}

class BranchPostingImages {
  int? id;
  String? imageName;
  String? imageUrl;
  String? imageStr;

  BranchPostingImages({this.id, this.imageName, this.imageUrl, this.imageStr});

  BranchPostingImages.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    imageName = json['imageName'];
    imageUrl = json['imageUrl'];
    imageStr = json['imageStr'];
  }
}
