import 'package:mc_common_app/extensions/string_extensions.dart';
import 'package:mc_common_app/models/advertisment_models/ad_details_model.dart';
import 'package:mc_common_app/models/provider_branches_models/profile/categroy.dart';
import 'package:mc_common_app/models/services_models/service_model.dart';
import 'package:mc_common_app/utils/enums.dart';

class BranchDetailModel {
  int? id;
  int? serviceProviderId;
  String? serviceProviderName;
  String? branchProfileImage;
  String? branchName;
  String? branchDescription;
  int? cityId;
  String? cityName;
  String? address;
  String? latitude;
  String? longitude;
  double? distanceKm;
  String? openTime;
  String? closeTime;
  BranchStatusEnum? branchStatus;
  List<GenericImageModel>? branchImages;
  int? statusId;
  String? statusText;
  String? branchStatusLabel;
  double? branchRateAvg;
  List<ServiceModel>? branchServices;
  List<CategoryData>? categories;
  List<BranchAuditTrial>? branchAuditTrial;
  int? countryID;
  String? countryName;
  bool isExpanded = false;
  bool? isFavorite;


  BranchDetailModel({
    this.id,
    this.serviceProviderId,
    this.serviceProviderName,
    this.branchProfileImage,
    this.branchName,
    this.branchDescription,
    this.cityId,
    this.cityName,
    this.address,
    this.latitude,
    this.longitude,
    this.distanceKm,
    this.openTime,
    this.closeTime,
    this.branchStatus,
    this.branchImages,
    this.branchRateAvg,
    this.statusId,
    this.statusText,
    this.branchStatusLabel,
    this.branchServices,
    this.categories,
    this.branchAuditTrial,
    this.countryID,
    this.countryName,
    this.isFavorite,
    required this.isExpanded,
  });

  List<GenericImageModel> populateBranchImages(value) {
    List<GenericImageModel> images = [];
    if (value != null) {
      value.forEach((v) {
        images.add(GenericImageModel.fromJson(v));
      });
    }
    return images;
  }

  BranchDetailModel.fromJson(Map<String, dynamic> json) {
    List<GenericImageModel> images = [];
    if (json.containsKey('serviceProviderBranchImage')) {
      images = populateBranchImages(json["serviceProviderBranchImage"]);
    } else {
      images = populateBranchImages(json["branchImages"]);
    }
    id = json["id"];
    serviceProviderId = json["serviceProviderID"];
    branchProfileImage = images.isNotEmpty ? images.first.imageUrl ?? "" : null;
    serviceProviderName = json["serviceProviderName"];
    branchName = json["branchName"];
    branchDescription = json["branchDescription"];
    cityId = json["cityID"];
    cityName = json["cityName"];
    address = json["address"];
    latitude = json["latitude"];
    longitude = json["longitude"];
    distanceKm = json["distanceKM"]?.toDouble();
    openTime = json["openTime"];
    closeTime = json["closeTime"];
    branchStatus = json.containsKey("branchStatus") ? (json['branchStatus'] as int).toBranchStatusEnum() : null;
    statusId = json["branchStatus"];
    branchImages = images;
    statusText = json["statusText"];
    branchStatusLabel = json["branchStatusText"];
    branchRateAvg = json["branchRateAvg"];
    branchServices = json["serviceProviderServices"] == null ? [] : List<ServiceModel>.from(json["serviceProviderServices"]!.map((x) => ServiceModel.fromJson(x)));
    categories = [];
    branchAuditTrial = json["branchAuditTrial"] == null ? [] : List<BranchAuditTrial>.from(json["branchAuditTrial"]!.map((x) => BranchAuditTrial.fromJson(x)));
    isExpanded = false;
    isFavorite = false;
  }
}

class BranchAuditTrial {
  int? status;
  String? comment;
  int? createdBy;
  String? createdOn;

  BranchAuditTrial({this.status, this.comment, this.createdBy, this.createdOn});

  BranchAuditTrial.fromJson(Map<String, dynamic> json) {
    status = json['status'];
    comment = json['comment'];
    createdBy = json['createdBy'];
    createdOn = json['createdOn'];
  }
}
