import 'dart:convert';

// ignore_for_file: depend_on_referenced_packages
import 'package:admin/app/models/admin_commission_model.dart';
import 'package:admin/app/models/location_lat_lng.dart';
import 'package:admin/app/models/positions.dart';
import 'package:admin/app/models/subscription_model.dart';
import 'package:admin/app/models/verify_driver_model.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class DriverUserModel {
  String? fullName;
  String? slug;
  String? id;
  String? email;
  String? loginType;
  String? profilePic;
  String? dateOfBirth;
  String? fcmToken;
  String? countryCode;
  String? phoneNumber;
  String? walletAmount;
  String? totalEarning;
  String? gender;
  bool? isActive;
  bool? isVerified;
  bool? isOnline;
  Timestamp? createdAt;
  DriverVehicleDetails? driverVehicleDetails;
  List<VerifyDocumentModel>? verifyDocument;
  LocationLatLng? location;
  Positions? position;
  dynamic rotation;
  String? reviewsCount;
  String? reviewsSum;
  AdminCommission? adminCommission;
  String? subscriptionPlanId;
  Timestamp? subscriptionExpiryDate;
  String? subscriptionTotalBookings;
  SubscriptionModel? subscriptionPlan;
  String? status;
  String? bookingId;
  List<String>? zoneId;
  List<dynamic>? searchNameKeywords;
  List<dynamic>? searchEmailKeywords;

  DriverUserModel({
    this.fullName,
    this.slug,
    this.driverVehicleDetails,
    this.verifyDocument,
    this.location,
    this.position,
    this.id,
    this.isActive,
    this.isVerified,
    this.isOnline,
    this.dateOfBirth,
    this.email,
    this.loginType,
    this.profilePic,
    this.fcmToken,
    this.countryCode,
    this.phoneNumber,
    this.walletAmount,
    this.totalEarning,
    this.createdAt,
    this.rotation,
    this.gender,
    this.reviewsCount,
    this.reviewsSum,
    this.adminCommission,
    this.subscriptionPlanId,
    this.subscriptionExpiryDate,
    this.subscriptionTotalBookings,
    this.subscriptionPlan,
    this.status,
    this.bookingId,
    this.zoneId,
    this.searchNameKeywords,
    this.searchEmailKeywords,
  });

  DriverUserModel.fromJson(Map<String, dynamic> json) {
    fullName = json['fullName'];
    slug = json['slug'];
    id = json['id'];
    email = json['email'];
    loginType = json['loginType'];
    profilePic = json['profilePic'];
    fcmToken = json['fcmToken'];
    countryCode = json['countryCode'];
    phoneNumber = json['phoneNumber'];
    walletAmount = json['walletAmount'] ?? "0";
    totalEarning = json['totalEarning'] ?? "0";
    createdAt = json['createdAt'];
    gender = json['gender'];
    dateOfBirth = json['dateOfBirth'] ?? '';
    isActive = json['isActive'] ?? false;
    isOnline = json['isOnline'] ?? false;
    driverVehicleDetails = json['driverVehicleDetails'] != null ? DriverVehicleDetails.fromJson(json["driverVehicleDetails"]) : null;
    if (json['verifyDocument'] != null) {
      verifyDocument = List<VerifyDocumentModel>.from(
        (json['verifyDocument'] as List).map((x) => VerifyDocumentModel.fromJson(x)),
      );
    } else {
      verifyDocument = [];
    }
    isVerified = json['isVerified'] ?? false;
    location = json['location'] != null ? LocationLatLng.fromJson(json['location']) : LocationLatLng();
    position = json['position'] != null ? Positions.fromJson(json['position']) : Positions();
    rotation = json['rotation'];
    reviewsCount = json['reviewsCount'];
    reviewsSum = json['reviewsSum'];
    adminCommission = json['adminCommission'] != null ? AdminCommission.fromJson(json['adminCommission']) : AdminCommission();
    subscriptionPlanId = json['subscriptionPlanId'];
    subscriptionExpiryDate = json['subscriptionExpiryDate'];
    subscriptionTotalBookings = json['subscriptionTotalBookings'];
    subscriptionPlan = json['subscriptionPlan'] != null ? SubscriptionModel.fromJson(json['subscriptionPlan']) : SubscriptionModel();
    status = json['status'] ?? 'free';
    bookingId = json['bookingId'] ?? '';
    zoneId = List<String>.from(json['zoneId'] ?? []);
    searchNameKeywords = json['searchNameKeywords'] ?? [];
    searchEmailKeywords = json['searchEmailKeywords'] ?? [];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['fullName'] = fullName;
    data['slug'] = slug;
    data['id'] = id;
    data['email'] = email;
    data['loginType'] = loginType;
    data['profilePic'] = profilePic;
    data['fcmToken'] = fcmToken;
    data['countryCode'] = countryCode;
    data['phoneNumber'] = phoneNumber;
    data['walletAmount'] = walletAmount ?? '0.0';
    data['totalEarning'] = totalEarning ?? '0.0';
    data['createdAt'] = createdAt;
    data['gender'] = gender;
    data['dateOfBirth'] = dateOfBirth;
    data['isActive'] = isActive ?? false;
    data['isOnline'] = isOnline ?? false;
    data['isVerified'] = isVerified ?? false;
    if (driverVehicleDetails != null) {
      data["driverVehicleDetails"] = driverVehicleDetails!.toJson();
    }
    if (verifyDocument != null) {
      data['verifyDocument'] = List<dynamic>.from(verifyDocument!.map((x) => x.toJson()));
    }

    if (location != null) {
      data['location'] = location!.toJson();
    }
    if (position != null) {
      data['position'] = position!.toJson();
    }
    data['rotation'] = rotation;
    data['reviewsCount'] = reviewsCount ?? '0';
    data['reviewsSum'] = reviewsSum ?? "0.0";
    if (adminCommission != null) {
      data['adminCommission'] = adminCommission!.toJson();
    }
    data['subscriptionPlanId'] = subscriptionPlanId;
    data['subscriptionExpiryDate'] = subscriptionExpiryDate;
    data['subscriptionTotalBookings'] = subscriptionTotalBookings;
    if (subscriptionPlan != null) {
      data['subscriptionPlan'] = subscriptionPlan!.toJson();
    }
    data['status'] = status;
    data['bookingId'] = bookingId;
    data['zoneId'] = zoneId;
    data['searchNameKeywords'] = searchNameKeywords;
    data['searchEmailKeywords'] = searchEmailKeywords;
    return data;
  }
}

class DriverVehicleDetails {
  String? vehicleTypeName;
  String? vehicleTypeId;
  String? brandName;
  String? brandId;
  String? modelName;
  String? modelId;
  String? vehicleNumber;

  DriverVehicleDetails({
    this.vehicleTypeName,
    this.vehicleTypeId,
    this.brandName,
    this.brandId,
    this.modelName,
    this.modelId,
    this.vehicleNumber,
  });

  factory DriverVehicleDetails.fromRawJson(String str) => DriverVehicleDetails.fromJson(json.decode(str));

  String toRawJson() => json.encode(toJson());

  factory DriverVehicleDetails.fromJson(Map<String, dynamic> json) => DriverVehicleDetails(
        vehicleTypeName: json["vehicleTypeName"],
        vehicleTypeId: json["vehicleTypeId"],
        brandName: json["brandName"],
        brandId: json["brandId"],
        modelName: json["modelName"],
        modelId: json["modelId"],
        vehicleNumber: json["vehicleNumber"],
      );

  Map<String, dynamic> toJson() => {
        "vehicleTypeName": vehicleTypeName ?? '',
        "vehicleTypeId": vehicleTypeId ?? '',
        "brandName": brandName ?? '',
        "brandId": brandId ?? '',
        "modelName": modelName ?? '',
        "modelId": modelId ?? '',
        "vehicleNumber": vehicleNumber ?? '',
      };
}
