import 'package:equatable/equatable.dart';

class PaginatedDataModel<T> extends Equatable {
  const PaginatedDataModel({
    required this.data,
    required this.page,
    required this.size,
    required this.hasNext,
    required this.totalItems,
    required this.totalPages,
  });

  final List<T> data;
  final int page;
  final int size;
  final bool hasNext;
  final int totalItems;
  final int totalPages;

  factory PaginatedDataModel.fromJson(
    Map<String, dynamic> json,
    List<T> Function(List<dynamic>) fromJsonList,
  ) {
    return PaginatedDataModel<T>(
      data: fromJsonList(json['data'] as List<dynamic>),
      page: json['page'] as int? ?? 1,
      size: json['size'] as int? ?? 25,
      hasNext: json['hasNext'] as bool? ?? false,
      totalItems: json['totalItem'] as int? ?? 0,
      totalPages: json['totalPage'] as int? ?? 0,
    );
  }

  @override
  List<Object?> get props => [
        data,
        page,
        size,
        hasNext,
        totalItems,
        totalPages,
      ];
}
