class AllOrganizationListResponse {
  final bool success;
  final String message;
  final OrganizationData data;
  final dynamic errors;
  final int statusCode;
  final String timestamp;

  AllOrganizationListResponse({
    required this.success,
    required this.message,
    required this.data,
    this.errors,
    required this.statusCode,
    required this.timestamp,
  });

  factory AllOrganizationListResponse.fromJson(Map<String, dynamic> json) {
    return AllOrganizationListResponse(
      success: json['success'] ?? false,
      message: json['message'] ?? '',
      data: json['data'] != null
          ? OrganizationData.fromJson(json['data'])
          : OrganizationData(currentPage: 0, totalPages: 0, totalEntities: 0, data: []),
      errors: json['errors'],
      statusCode: json['statusCode'] ?? 0,
      timestamp: json['timestamp'] ?? '',
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'success': success,
      'message': message,
      'data': data.toJson(),
      'errors': errors,
      'statusCode': statusCode,
      'timestamp': timestamp,
    };
  }
}

class OrganizationData {
  final int currentPage;
  final int totalPages;
  final int totalEntities;
  final List<AllOrganization> data;

  OrganizationData({
    required this.currentPage,
    required this.totalPages,
    required this.totalEntities,
    required this.data,
  });

  factory OrganizationData.fromJson(Map<String, dynamic> json) {
    return OrganizationData(
      currentPage: json['currentPage'] ?? 0,
      totalPages: json['totalPages'] ?? 0,
      totalEntities: json['totalEntities'] ?? 0,
      data: (json['data'] as List<dynamic>?)
              ?.map((e) => AllOrganization.fromJson(e))
              .toList() ??
          [],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'currentPage': currentPage,
      'totalPages': totalPages,
      'totalEntities': totalEntities,
      'data': data.map((e) => e.toJson()).toList(),
    };
  }
}

class AllOrganization {
  final String id;
  final String name;
  final String email;
  final String contactPerson;
  final String address;
  final String contactNumber;
  final int sprid;
  final String? logoImage;
  final String createdAt;
  final User? createdBy;
  final User? updatedBy;
  final String? updatedAt;
  final bool isActive;

  AllOrganization({
    required this.id,
    required this.name,
    required this.email,
    required this.contactPerson,
    required this.address,
    required this.contactNumber,
    required this.sprid,
    this.logoImage,
    required this.createdAt,
    this.createdBy,
    this.updatedBy,
    this.updatedAt,
    required this.isActive,
  });

  factory AllOrganization.fromJson(Map<String, dynamic> json) {
    return AllOrganization(
      id: json['id'] ?? '',
      name: json['name'] ?? '',
      email: json['email'] ?? '',
      contactPerson: json['contactPerson'] ?? '',
      address: json['address'] ?? '',
      contactNumber: json['contactNumber'] ?? '',
      sprid: json['sprid'] ?? 0,
      logoImage: json['logoImage'],
      createdAt: json['createdAt'] ?? '',
      createdBy: json['createdBy'] != null ? User.fromJson(json['createdBy']) : null,
      updatedBy: json['updatedBy'] != null ? User.fromJson(json['updatedBy']) : null,
      updatedAt: json['updatedAt'],
      isActive: json['isActive'] ?? false,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'email': email,
      'contactPerson': contactPerson,
      'address': address,
      'contactNumber': contactNumber,
      'sprid': sprid,
      'logoImage': logoImage,
      'createdAt': createdAt,
      'createdBy': createdBy?.toJson(),
      'updatedBy': updatedBy?.toJson(),
      'updatedAt': updatedAt,
      'isActive': isActive,
    };
  }
}

class User {
  final String id;
  final String firstName;
  final String lastName;
  final String photo;
  final String jobRoleId;
  final String jobRoleName;

  User({
    required this.id,
    required this.firstName,
    required this.lastName,
    required this.photo,
    required this.jobRoleId,
    required this.jobRoleName,
  });

  factory User.fromJson(Map<String, dynamic> json) {
    return User(
      id: json['id'] ?? '',
      firstName: json['firstName'] ?? '',
      lastName: json['lastName'] ?? '',
      photo: json['photo'] ?? '',
      jobRoleId: json['jobRoleId'] ?? '',
      jobRoleName: json['jobRoleName'] ?? '',
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'firstName': firstName,
      'lastName': lastName,
      'photo': photo,
      'jobRoleId': jobRoleId,
      'jobRoleName': jobRoleName,
    };
  }
}
