class GroupDetail {
  String? id;
  String? type;
  String? name;
  String? description;
  String? ownerId;
  String? status;
  String? visibility;
  DateTime? createdAt;
  DateTime? updatedAt;
  List<GroupUser>? users;
  List<DeviceOfGroup>? devices;

  GroupDetail({
    required this.id,
    this.type,
    this.name,
    this.description,
    this.ownerId,
    this.status,
    this.visibility,
    this.createdAt,
    this.updatedAt,
    this.users,
    this.devices,
  });

  GroupDetail.fromJson(Map<String, dynamic> json) {
    id = json["id"];
    type = json["type"];
    name = json["name"];
    description = json["description"];
    ownerId = json["ownerId"];
    status = json["status"];
    visibility = json["visibility"];
    createdAt = DateTime.parse(json["created_at"]);
    updatedAt = DateTime.parse(json['updated_at']);
    if (json['users'] != null) {
      users = [];
      json["users"].forEach((v) {
        final user = GroupUser.fromJson(v);
        users!.add(user);
      });
    }
    if (json['devices'] != null) {
      devices = [];
      json["devices"].forEach((v) {
        final device = DeviceOfGroup.fromJson(v);
        devices!.add(device);
      });
    }
  }

  // static List<GroupDetail> fromJsonDynamicList(List<dynamic> list) {
  //   return list.map((e) => GroupDetail.fromJson(e)).toList();
  // }
}

class GroupUser {
  String? id;
  String? username;
  String? role;
  String? name;
  String? email;
  String? phone;
  bool? isOwner;
  String? status;
  String? address;
  String? latitude;
  String? longitude;

  GroupUser({
    required this.id,
    this.username,
    this.role,
    this.name,
    this.email,
    this.phone,
    this.isOwner,
    this.status,
    this.address,
    this.latitude,
    this.longitude,
  });

  GroupUser.fromJson(Map<String, dynamic> json) {
    id = json["id"];
    username = json["username"];
    role = json["role"];
    name = json["name"];
    email = json['email'];
    phone = json['phone'];
    isOwner = json['is_owner'];
    status = json['status'];
    address = json['address'];
    latitude = json['latitude'];
    longitude = json['longitude'];
  }

  static List<GroupUser> fromJsonList(List list) {
    return list.map((e) => GroupUser.fromJson(e)).toList();
  }

  static List<GroupUser> fromJsonDynamicList(List<dynamic> list) {
    return list.map((e) => GroupUser.fromJson(e)).toList();
  }
}

class DeviceOfGroup {
  String? thingId;
  String? name;
  String? alias;
  DateTime? connectionTime;
  int? state;
  String? visibility;

  DeviceOfGroup({
    required this.thingId,
    this.name,
    this.alias,
    this.connectionTime,
    this.state,
    this.visibility,
  });
  DeviceOfGroup.fromJson(Map<String, dynamic> json) {
    thingId = json['thing_id'];
    name = json['name'];
    alias = json['alias'];
    connectionTime = DateTime.parse(json['connection_time']);
    state = json['state'];
    visibility = json['visibility'];
  }
}
