import 'dart:convert';

class PrivateMeetingsModel {
  List<DatumInPrivateMeeting>? data;

  PrivateMeetingsModel({
    this.data,
  });

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

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

  factory PrivateMeetingsModel.fromJson(Map<String, dynamic> json) =>
      PrivateMeetingsModel(
        data: json["data"] == null
            ? []
            : List<DatumInPrivateMeeting>.from(
                json["data"]!.map((x) => DatumInPrivateMeeting.fromJson(x))),
      );

  Map<String, dynamic> toJson() => {
        "data": data == null
            ? []
            : List<dynamic>.from(data!.map((x) => x.toJson())),
      };
  hasData() => this.data != null && this.data!.isNotEmpty;
}

class DatumInPrivateMeeting {
  int? id;
  int? locationsId;
  int? subjectId;
  int? managerId;
  int? ownerId;
  String? azHour;
  String? taHour;
  String? description;
  int? status;
  int? accepted;
  String? visitName;
  String? visitMobile;
  String? visitRole;
  String? visitCompany;
  DateTime? dateMeeting;
  DateTime? endDate;
  DateTime? createdAt;
  DateTime? updatedAt;
  String? dateJalali;
  StatusTxt? statusTxt;
  String? az;
  String? ta;
  List<String>? minutes;
  Location? location;
  Subject? subject;
  Manager? manager;

  DatumInPrivateMeeting({
    this.id,
    this.locationsId,
    this.subjectId,
    this.managerId,
    this.ownerId,
    this.azHour,
    this.taHour,
    this.description,
    this.status,
    this.accepted,
    this.visitName,
    this.visitMobile,
    this.visitRole,
    this.visitCompany,
    this.dateMeeting,
    this.endDate,
    this.createdAt,
    this.updatedAt,
    this.dateJalali,
    this.statusTxt,
    this.az,
    this.ta,
    this.minutes,
    this.location,
    this.subject,
    this.manager,
  });

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

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

  factory DatumInPrivateMeeting.fromJson(Map<String, dynamic> json) =>
      DatumInPrivateMeeting(
        id: json["id"],
        locationsId: json["locations_id"],
        subjectId: json["subject_id"],
        managerId: json["manager_id"],
        ownerId: json["owner_id"],
        azHour: json["az_hour"],
        taHour: json["ta_hour"],
        description: json["description"],
        status: json["status"],
        accepted: json["accepted"],
        visitName: json["visit_name"],
        visitMobile: json["visit_mobile"],
        visitRole: json["visit_role"],
        visitCompany: json["visit_company"],
        dateMeeting: json["date_meeting"] == null
            ? null
            : DateTime.parse(json["date_meeting"]),
        endDate:
            json["end_date"] == null ? null : DateTime.parse(json["end_date"]),
        createdAt: json["created_at"] == null
            ? null
            : DateTime.parse(json["created_at"]),
        updatedAt: json["updated_at"] == null
            ? null
            : DateTime.parse(json["updated_at"]),
        dateJalali: json["date_jalali"],
        statusTxt: statusTxtValues.map[json["status_txt"]]!,
        az: json["az"],
        ta: json["ta"],
        minutes: json["minutes"] == null
            ? []
            : List<String>.from(json["minutes"]!.map((x) => x)),
        location: json["location"] == null
            ? null
            : Location.fromJson(json["location"]),
        subject:
            json["subject"] == null ? null : Subject.fromJson(json["subject"]),
        manager:
            json["manager"] == null ? null : Manager.fromJson(json["manager"]),
      );

  Map<String, dynamic> toJson() => {
        "id": id,
        "locations_id": locationsId,
        "subject_id": subjectId,
        "manager_id": managerId,
        "owner_id": ownerId,
        "az_hour": azHour,
        "ta_hour": taHour,
        "description": description,
        "status": status,
        "accepted": accepted,
        "visit_name": visitName,
        "visit_mobile": visitMobile,
        "visit_role": visitRole,
        "visit_company": visitCompany,
        "date_meeting": dateMeeting?.toIso8601String(),
        "end_date": endDate?.toIso8601String(),
        "created_at": createdAt?.toIso8601String(),
        "updated_at": updatedAt?.toIso8601String(),
        "date_jalali": dateJalali,
        "status_txt": statusTxtValues.reverse[statusTxt],
        "az": az,
        "ta": ta,
        "minutes":
            minutes == null ? [] : List<dynamic>.from(minutes!.map((x) => x)),
        "location": location?.toJson(),
        "subject": subject?.toJson(),
        "manager": manager?.toJson(),
      };
}

class Location {
  int? id;
  String? address;
  String? addressEn;
  DateTime? createdAt;
  DateTime? updatedAt;

  Location({
    this.id,
    this.address,
    this.addressEn,
    this.createdAt,
    this.updatedAt,
  });

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

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

  factory Location.fromJson(Map<String, dynamic> json) => Location(
        id: json["id"],
        address: json["address"],
        addressEn: json["address_en"],
        createdAt: json["created_at"] == null
            ? null
            : DateTime.parse(json["created_at"]),
        updatedAt: json["updated_at"] == null
            ? null
            : DateTime.parse(json["updated_at"]),
      );

  Map<String, dynamic> toJson() => {
        "id": id,
        "address": address,
        "address_en": addressEn,
        "created_at": createdAt?.toIso8601String(),
        "updated_at": updatedAt?.toIso8601String(),
      };
}

class Manager {
  int? id;
  Name? name;
  int? role;
  String? mobile;
  dynamic otp;
  dynamic access;
  dynamic managerId;
  dynamic firebaseToken;
  int? isBlock;
  int? getSms;
  DateTime? createdAt;
  DateTime? updatedAt;

  Manager({
    this.id,
    this.name,
    this.role,
    this.mobile,
    this.otp,
    this.access,
    this.managerId,
    this.firebaseToken,
    this.isBlock,
    this.getSms,
    this.createdAt,
    this.updatedAt,
  });

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

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

  factory Manager.fromJson(Map<String, dynamic> json) => Manager(
        id: json["id"],
        name: nameValues.map[json["name"]],
        role: json["role"],
        mobile: json["mobile"],
        otp: json["otp"],
        access: json["access"],
        managerId: json["manager_id"],
        firebaseToken: json["firebase_token"],
        isBlock: json["is_block"],
        getSms: json["get_sms"],
        createdAt: json["created_at"] == null
            ? null
            : DateTime.parse(json["created_at"]),
        updatedAt: json["updated_at"] == null
            ? null
            : DateTime.parse(json["updated_at"]),
      );

  Map<String, dynamic> toJson() => {
        "id": id,
        "name": nameValues.reverse[name],
        "role": role,
        "mobile": mobile,
        "otp": otp,
        "access": access,
        "manager_id": managerId,
        "firebase_token": firebaseToken,
        "is_block": isBlock,
        "get_sms": getSms,
        "created_at": createdAt?.toIso8601String(),
        "updated_at": updatedAt?.toIso8601String(),
      };
}

enum Name { ADMIN, ALI }

final nameValues = EnumValues({"Admin": Name.ADMIN, "Ali": Name.ALI});

enum StatusTxt { EMPTY, PURPLE, STATUS_TXT }

final statusTxtValues = EnumValues({
  "لغو شده": StatusTxt.EMPTY,
  "منتظر برگزاری": StatusTxt.PURPLE,
  "برگزار شده": StatusTxt.STATUS_TXT
});

class Subject {
  int? id;
  String? subject;
  String? subjectEn;
  DateTime? createdAt;
  DateTime? updatedAt;

  Subject({
    this.id,
    this.subject,
    this.subjectEn,
    this.createdAt,
    this.updatedAt,
  });

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

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

  factory Subject.fromJson(Map<String, dynamic> json) => Subject(
        id: json["id"],
        subject: json["subject"],
        subjectEn: json["subject_en"],
        createdAt: json["created_at"] == null
            ? null
            : DateTime.parse(json["created_at"]),
        updatedAt: json["updated_at"] == null
            ? null
            : DateTime.parse(json["updated_at"]),
      );

  Map<String, dynamic> toJson() => {
        "id": id,
        "subject": subject,
        "subject_en": subjectEn,
        "created_at": createdAt?.toIso8601String(),
        "updated_at": updatedAt?.toIso8601String(),
      };
}

class EnumValues<T> {
  Map<String, T> map;
  late Map<T, String> reverseMap;

  EnumValues(this.map);

  Map<T, String> get reverse {
    reverseMap = map.map((k, v) => MapEntry(v, k));
    return reverseMap;
  }
}
