// To parse this JSON data, do
//
//     final subscription = subscriptionFromJson(jsonString);

import 'dart:convert';

import 'package:mc_common_app/extensions/string_extensions.dart';

import '../../utils/enums.dart';

Subscription subscriptionFromJson(String str) => Subscription.fromJson(json.decode(str));

String subscriptionToJson(Subscription data) => json.encode(data.toJson());

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

  int? messageStatus;
  int? totalItemsCount;
  List<Subscription>? data;
  String? message;

  factory SubscriptionModel.fromJson(Map<String, dynamic> json) => SubscriptionModel(
        messageStatus: json["messageStatus"],
        totalItemsCount: json["totalItemsCount"],
        data: json["data"] == null ? [] : List<Subscription>.from(json["data"]!.map((x) => Subscription.fromJson(x))),
        message: json["message"],
      );

  Map<String, dynamic> toJson() => {
        "messageStatus": messageStatus,
        "totalItemsCount": totalItemsCount,
        "data": data == null ? [] : List<dynamic>.from(data!.map((x) => x.toJson())),
        "message": message,
      };
}

class Subscription {
  Subscription({
    this.id,
    this.name,
    this.description,
    this.durationName,
    this.durationDays,
    this.price,
    this.currency,
    this.numberOfBranches,
    this.numberOfSubUsers,
    this.numberOfAds,
    this.countryId,
    this.countryName,
    this.isSubscribed,
    this.subscriptionAppliedId,
    this.serviceProviderId,
    this.dateStart,
    this.dateEnd,
    this.isExpired,
    this.isActive,
    this.subscriptionTypeEnum,
    this.isMyCurrentPackage,
  });

  int? id;
  String? name;
  String? description;
  String? durationName;
  int? durationDays;
  double? price;
  String? currency;
  int? numberOfBranches;
  int? numberOfSubUsers;
  int? numberOfAds;
  int? countryId;
  String? countryName;
  bool? isSubscribed;
  int? subscriptionAppliedId;
  int? serviceProviderId;
  DateTime? dateStart;
  DateTime? dateEnd;
  bool? isExpired;
  bool? isActive;
  SubscriptionTypeEnum? subscriptionTypeEnum;
  bool? isMyCurrentPackage;

  factory Subscription.fromJson(Map<String, dynamic> json) => Subscription(
      id: json["id"],
      name: json["name"],
      description: json["description"],
      durationName: json["durationName"],
      durationDays: json["durationDays"],
      price: json["price"]?.toDouble(),
      currency: json["currency"],
      numberOfBranches: json["numberOfBranches"],
      numberOfSubUsers: json["numberOfSubUsers"],
      numberOfAds: json["numberOfAds"],
      countryId: json["countryID"],
      countryName: json["countryName"],
      isSubscribed: json["isSubscribed"],
      subscriptionAppliedId: json["subscriptionAppliedID"],
      serviceProviderId: json["serviceProviderID"],
      dateStart: json["dateStart"] == null ? null : DateTime.parse(json["dateStart"]),
      dateEnd: json["dateEnd"] == null ? null : DateTime.parse(json["dateEnd"]),
      isExpired: json["isExpired"],
      isActive: json["isActive"],
      isMyCurrentPackage: false,
      subscriptionTypeEnum: json["subscriptionType"] == null ? null : ((json['subscriptionType']) as int).toSubscriptionTypeEnum());

  Map<String, dynamic> toJson() => {
        "id": id,
        "name": name,
        "description": description,
        "durationName": durationName,
        "durationDays": durationDays,
        "price": price,
        "currency": currency,
        "numberOfBranches": numberOfBranches,
        "numberOfSubUsers": numberOfSubUsers,
        "numberOfAds": numberOfAds,
        "countryID": countryId,
        "countryName": countryName,
        "isSubscribed": isSubscribed,
        "subscriptionAppliedID": subscriptionAppliedId,
        "serviceProviderID": serviceProviderId,
        "dateStart": dateStart?.toIso8601String(),
        "dateEnd": dateEnd?.toIso8601String(),
        "isExpired": isExpired,
        "isActive": isActive,
      };
}
