import 'package:freezed_annotation/freezed_annotation.dart';
import 'response_meta.dart';

part 'api_response.freezed.dart';
part 'api_response.g.dart';

@Freezed(genericArgumentFactories: true)
class ApiResponse<T> with _$ApiResponse<T> {
  const ApiResponse._();
  
  const factory ApiResponse({
    required String status,      // "success" | "error"
    required String message,
    T? data,
    ResponseMeta? meta,          // 페이지네이션 등 메타데이터
    @JsonKey(name: 'error') Map<String, dynamic>? errorDetails,
  }) = _ApiResponse<T>;

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

  // 편의성을 위한 getter
  bool get isSuccess => status == 'success';
  bool get isError => status == 'error';
}