import 'package:mc_common_app/extensions/string_extensions.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 {
  final int? id;
  final int? serviceProviderId;
  final String? serviceProviderName;
  final String? branchName;
  final String? branchDescription;
  final int? cityId;
  final String? cityName;
  final String? address;
  final String? latitude;
  final String? longitude;
  final double? distanceKm;
  final String? openTime;
  final String? closeTime;
  final BranchStatusEnum? branchStatus;
  final int? statusId;
  final dynamic statusText;
  final List<ServiceModel>? branchServices;
  List<CategoryData>? categories;
  int? countryID;
  String? countryName;
  bool isExpanded;

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

  factory BranchDetailModel.fromJson(Map<String, dynamic> json) =>
      BranchDetailModel(
        id: json["id"],
        serviceProviderId: json["serviceProviderID"],
        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"],
        statusText: json["statusText"],
        branchServices: json["serviceProviderServices"] == null ? [] : List<
            ServiceModel>.from(json["serviceProviderServices"]!.map((x) =>
            ServiceModel.fromJson(x))),
        categories: [],
        isExpanded: false,
      );

  Map<String, dynamic> toJson() =>
      {
        "id": id,
        "serviceProviderID": serviceProviderId,
        "serviceProviderName": serviceProviderName,
        "branchName": branchName,
        "branchDescription": branchDescription,
        "cityID": cityId,
        "address": address,
        "latitude": latitude,
        "longitude": longitude,
        "distanceKM": distanceKm,
        "openTime": openTime,
        "closeTime": closeTime,
        "status": statusId,
        "statusText": statusText,
        "serviceProviderServices": branchServices == null ? [] : List<
            dynamic>.from(branchServices!.map((x) => x.toJson())),
      };
}
