class DocumentVersionsResponse {
  final bool success;
  final String message;
  final VersionDataWrapper data;
  final dynamic errors;
  final int statusCode;
  final DateTime timestamp;

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

  factory DocumentVersionsResponse.fromJson(Map<String, dynamic> json) {
    return DocumentVersionsResponse(
      success: json['success'] ?? false,
      message: json['message'] ?? "",
      data: VersionDataWrapper.fromJson(json['data']),
      errors: json['errors'],
      statusCode: json['statusCode'] ?? 0,
      timestamp: DateTime.parse(json['timestamp']),
    );
  }
}

class VersionDataWrapper {
  final int currentPage;
  final int totalPages;
  final int totalEntites;
  final List<DocumentVersionItem> data;

  VersionDataWrapper({
    required this.currentPage,
    required this.totalPages,
    required this.totalEntites,
    required this.data,
  });

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

class DocumentVersionItem {
  final String id;
  final String name;
  final String documentId;
  final int version;
  final int fileSize;
  final String contentType;
  final DateTime uploadedAt;
  final UserInfo uploadedBy;
  final DateTime? updatedAt;
  final UserInfo? updatedBy;
  final DateTime? verifiedAt;
  final UserInfo? verifiedBy;
  final bool? isVerified;

  DocumentVersionItem({
    required this.id,
    required this.name,
    required this.documentId,
    required this.version,
    required this.fileSize,
    required this.contentType,
    required this.uploadedAt,
    required this.uploadedBy,
    this.updatedAt,
    this.updatedBy,
    this.verifiedAt,
    this.verifiedBy,
    this.isVerified,
  });

  factory DocumentVersionItem.fromJson(Map<String, dynamic> json) {
    return DocumentVersionItem(
      id: json['id'] ?? "",
      name: json['name'] ?? "",
      documentId: json['documentId'] ?? "",
      version: json['version'] ?? 0,
      fileSize: json['fileSize'] ?? 0,
      contentType: json['contentType'] ?? "",
      uploadedAt: DateTime.parse(json['uploadedAt']),
      uploadedBy: UserInfo.fromJson(json['uploadedBy']),
      updatedAt:
          json['updatedAt'] != null ? DateTime.parse(json['updatedAt']) : null,
      updatedBy:
          json['updatedBy'] != null ? UserInfo.fromJson(json['updatedBy']) : null,
      verifiedAt: json['verifiedAt'] != null
          ? DateTime.tryParse(json['verifiedAt'])
          : null,
      verifiedBy:
          json['verifiedBy'] != null ? UserInfo.fromJson(json['verifiedBy']) : null,
      isVerified: json['isVerified'],
    );
  }
}

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

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

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