class ContactModel {
  final String id;
  final List<String>? projectIds;
  final String name;
  final String? designation; 
  final List<ContactPhone> contactPhones;
  final List<ContactEmail> contactEmails;
  final ContactCategory? contactCategory;
  final List<String> bucketIds;
  final String description;
  final String organization;
  final String address;
  final List<Tag> tags;

  ContactModel({
    required this.id,
    required this.projectIds,
    required this.name,
    this.designation, 
    required this.contactPhones,
    required this.contactEmails,
    required this.contactCategory,
    required this.bucketIds,
    required this.description,
    required this.organization,
    required this.address,
    required this.tags,
  });

  factory ContactModel.fromJson(Map<String, dynamic> json) {
    return ContactModel(
      id: json['id'],
      projectIds: (json['projectIds'] as List?)?.map((e) => e as String).toList(),
      name: json['name'],
      designation: json['designation'], 
      contactPhones: (json['contactPhones'] as List)
          .map((e) => ContactPhone.fromJson(e))
          .toList(),
      contactEmails: (json['contactEmails'] as List)
          .map((e) => ContactEmail.fromJson(e))
          .toList(),
      contactCategory: json['contactCategory'] != null
          ? ContactCategory.fromJson(json['contactCategory'])
          : null,
      bucketIds: (json['bucketIds'] as List).map((e) => e as String).toList(),
      description: json['description'],
      organization: json['organization'],
      address: json['address'],
      tags: (json['tags'] as List).map((e) => Tag.fromJson(e)).toList(),
    );
  }
}


class ContactPhone {
  final String id;
  final String label;
  final String phoneNumber;
  final String contactId;

  ContactPhone({
    required this.id,
    required this.label,
    required this.phoneNumber,
    required this.contactId,
  });

  factory ContactPhone.fromJson(Map<String, dynamic> json) {
    return ContactPhone(
      id: json['id'],
      label: json['label'],
      phoneNumber: json['phoneNumber'],
      contactId: json['contactId'],
    );
  }
}

class ContactEmail {
  final String id;
  final String label;
  final String emailAddress;
  final String contactId;

  ContactEmail({
    required this.id,
    required this.label,
    required this.emailAddress,
    required this.contactId,
  });

  factory ContactEmail.fromJson(Map<String, dynamic> json) {
    return ContactEmail(
      id: json['id'],
      label: json['label'],
      emailAddress: json['emailAddress'],
      contactId: json['contactId'],
    );
  }
}

class ContactCategory {
  final String id;
  final String name;
  final String description;

  ContactCategory({
    required this.id,
    required this.name,
    required this.description,
  });

  factory ContactCategory.fromJson(Map<String, dynamic> json) {
    return ContactCategory(
      id: json['id'],
      name: json['name'],
      description: json['description'],
    );
  }
}

class Tag {
  final String id;
  final String name;
  final String description;

  Tag({
    required this.id,
    required this.name,
    required this.description,
  });

  factory Tag.fromJson(Map<String, dynamic> json) {
    return Tag(
      id: json['id'],
      name: json['name'],
      description: json['description'],
    );
  }
}
