import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:superport/core/constants/app_constants.dart';

part 'pagination_params.freezed.dart';
part 'pagination_params.g.dart';

/// 페이지네이션 요청 파라미터를 위한 표준화된 클래스
@freezed
class PaginationParams with _$PaginationParams {
  const factory PaginationParams({
    @Default(1) int page,
    @Default(AppConstants.defaultPageSize) int perPage,
    String? search,
    String? sortBy,
    @Default('asc') String sortOrder,
    Map<String, dynamic>? filters,
  }) = _PaginationParams;

  factory PaginationParams.fromJson(Map<String, dynamic> json) =>
      _$PaginationParamsFromJson(json);
}

/// 페이지네이션 메타데이터
@freezed
class PaginationMeta with _$PaginationMeta {
  const factory PaginationMeta({
    required int currentPage,
    required int perPage,
    required int total,
    required int totalPages,
    required bool hasNext,
    required bool hasPrevious,
  }) = _PaginationMeta;

  factory PaginationMeta.fromJson(Map<String, dynamic> json) =>
      _$PaginationMetaFromJson(json);
}

/// 페이지네이션된 결과를 위한 래퍼 클래스
@Freezed(genericArgumentFactories: true)
class PagedResult<T> with _$PagedResult<T> {
  const factory PagedResult({
    required List<T> items,
    required PaginationMeta meta,
  }) = _PagedResult<T>;

  factory PagedResult.fromJson(
    Map<String, dynamic> json,
    T Function(Object?) fromJsonT,
  ) =>
      _$PagedResultFromJson<T>(json, fromJsonT);
}