import 'package:json_annotation/json_annotation.dart';

part 'APIResponse.g.dart';

@JsonSerializable()
class APIResponse <T>{
  @JsonKey(name: "status")
  String status;
  @JsonKey(name: "current_page")
  int currentPage;
  @JsonKey(name: "per_page")
  int perPage;
  @JsonKey(name: "total")
  int totalPages;
  @JsonKey(name: "last_page")
  int lastPage;
  @JsonKey(name: 'data')
  @_Converter()
  final T data;
  
  

  APIResponse({this.data});

  factory APIResponse.fromJson(Map<dynamic, dynamic> json) => _$APIResponseFromJson<T>(json);
  Map<dynamic, dynamic> toJson() => _$APIResponseToJson(this);

}

class _Converter<T> implements JsonConverter<T, Object> {
  const _Converter();

  @override
  T fromJson(Object json) {
    // This will only work if `json` is a native JSON type:
    //   num, String, bool, null, etc
    // *and* is assignable to `T`.
    return json as T;
  }

  @override
  Object toJson(T object) {
    // This will only work if `object` is a native JSON type:
    //   num, String, bool, null, etc
    // Or if it has a `toJson()` function`.
    return object;
  }
}