import 'package:mc_common_app/extensions/string_extensions.dart';
import 'package:mc_common_app/models/services_models/service_model.dart';
import 'package:mc_common_app/utils/enums.dart';

class AppointmentListModel {
  int? id;
  int? serviceSlotID;
  int? appointmentStatusID;
  String? appointmentStatusText;
  int? serviceProviderID;
  int? customerID;
  bool? isActive;
  bool? isPaymentRequired;
  int? paymentStatus;
  String? paymentStatusText;
  String? customerName;
  String? customerMobileNum;
  int? appointmentType;
  AppointmentTypeEnum? appointmentTypeEnum;

  String? providerName;
  String? duration;
  String? appointmentDate;
  String? paymentType;
  String? appointmentAddress;
  String? appointmentLatitude;
  String? appointmentLongitude;
  String? branchName;
  int? branchId;
  int? servicePaymentStatus;
  double? totalAmount;
  double? remainingAmount;
  bool? isSelected;
  bool? isMerged;
  AppointmentStatusEnum? appointmentStatusEnum;
  AppointmentPaymentStatusEnum? appointmentPaymentStatusEnum;
  List<ServiceModel>? appointmentServicesList;
  List<AppointmentListModel>? customerAppointmentList;
  List<MergeAppointmentList>? mergeAppointmentList;

  AppointmentListModel({
    this.id,
    this.serviceSlotID,
    this.appointmentStatusID,
    this.appointmentStatusText,
    this.serviceProviderID,
    this.customerID,
    this.isActive,
    this.isPaymentRequired,
    this.paymentStatus,
    this.paymentStatusText,
    this.customerName,
    this.customerMobileNum,
    this.appointmentType,
    this.appointmentTypeEnum,
    this.providerName,
    this.paymentType,
    this.appointmentAddress,
    this.appointmentLatitude,
    this.appointmentLongitude,
    this.branchName,
    this.branchId,
    this.servicePaymentStatus,
    this.totalAmount,
    this.remainingAmount,
    this.isSelected,
    this.appointmentDate,
    this.appointmentServicesList,
    this.customerAppointmentList,
    this.mergeAppointmentList,
  });

  @override
  String toString() {
    return 'AppointmentListModel{id: $id, serviceSlotID: $serviceSlotID, appointmentStatusID: $appointmentStatusID, appointmentStatusText: $appointmentStatusText, serviceProviderID: $serviceProviderID, customerID: $customerID, isActive: $isActive, isPaymentRequired: $isPaymentRequired, paymentStatus: $paymentStatus, paymentStatusText: $paymentStatusText, customerName: $customerName, providerName: $providerName, duration: $duration, appointmentDate: $appointmentDate, appointmentStatusEnum: $appointmentStatusEnum, appointmentServicesList: $appointmentServicesList}';
  }

  AppointmentListModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    serviceSlotID = json['serviceSlotID'];
    appointmentStatusID = json['appointmentStatusID'];
    appointmentStatusText = json['appointmentStatusText'];
    serviceProviderID = json['serviceProviderID'];
    customerID = json['customerID'];
    isActive = json['isActive'];
    isPaymentRequired = json['isPaymentRequired'];
    paymentStatus = json['paymentStatus'];
    paymentStatusText = json['paymentStatusText'];
    customerName = json['customerName'];
    customerMobileNum = json['customerMobile'];
    appointmentType = json['appointmentType'];
    appointmentTypeEnum = json['appointmentType'] != null ? (json['appointmentType'] as int).toAppointmentTypeEnum() : AppointmentTypeEnum.workshop;
    providerName = json['providerName'];
    duration = json['duration'];
    appointmentDate = json['appointmentDate'];
    paymentType = json['paymentType'];
    appointmentAddress = json['address'] ?? "";
    appointmentLatitude = json['branchLatitude'];
    appointmentLongitude = json['branchLongitude'];
    branchName = json['branchName'];
    branchId = json['branchID'];
    servicePaymentStatus = json['servicePaymentStatus'];
    totalAmount = json['amountTotal'];
    remainingAmount = json['amountRem'];
    isSelected = false;
    appointmentStatusEnum = (json['appointmentStatusID'] as int).toAppointmentStatusEnum();
    appointmentPaymentStatusEnum = (json['servicePaymentStatus'] as int).toAppointmentPaymentStatusEnum();
    if (json['serviceList'] != null) {
      appointmentServicesList = <ServiceModel>[];
      json['serviceList'].forEach((v) {
        appointmentServicesList!.add(ServiceModel.fromJson(v, isForAppointment: true));
      });
    }
    mergeAppointmentList = json["mergeAppointmentList"] == null ? [] : List<MergeAppointmentList>.from(json["mergeAppointmentList"]!.map((x) => MergeAppointmentList.fromJson(x)));
  }
}

class ServiceAppointmentItems {
  int? id;
  int? serviceItemID;
  String? serviceItemName;
  String? serviceItemDescription;

  ServiceAppointmentItems({this.id, this.serviceItemID, this.serviceItemName, this.serviceItemDescription});

  ServiceAppointmentItems.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    serviceItemID = json['serviceItemID'];
    serviceItemName = json['serviceItemName'];
    serviceItemDescription = json['serviceItemDescription'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['serviceItemID'] = serviceItemID;
    data['serviceItemName'] = serviceItemName;
    data['serviceItemDescription'] = serviceItemDescription;
    return data;
  }
}

// Data Model Class with 'customerName' and 'customerID'
class CustomerData {
  final int customerID;
  final String customerName;
  final List<AppointmentListModel> appointmentList;

  CustomerData({required this.customerID, required this.customerName, required this.appointmentList});
}

class MergeAppointmentList {
  int? id;
  int? mergeAppointmentId;
  int? serviceAppointmentId;

  MergeAppointmentList({
    this.id,
    this.mergeAppointmentId,
    this.serviceAppointmentId,
  });

  factory MergeAppointmentList.fromJson(Map<String, dynamic> json) => MergeAppointmentList(
        id: json["id"],
        mergeAppointmentId: json["mergeAppointmentID"],
        serviceAppointmentId: json["serviceAppointmentID"],
      );

  Map<String, dynamic> toJson() => {
        "id": id,
        "mergeAppointmentID": mergeAppointmentId,
        "serviceAppointmentID": serviceAppointmentId,
      };
}
