import 'package:clean/utils/expand.dart';
import 'package:json_annotation/json_annotation.dart';

part 'store_item.g.dart';

@JsonSerializable()
class StoreItem {
  @JsonKey(name: "id")
  late int id;
  @JsonKey(name: "sort")
  late int sort;
  @JsonKey(name: "name")
  late String name;
  @JsonKey(name: "appleGoodsId")
  late String appleGoodsId;
  @JsonKey(name: "subscribable")
  late int subscribable;
  @JsonKey(name: "amount")
  late int amount;
  @JsonKey(name: "originalAmount")
  late int originalAmount;
  @JsonKey(name: "auth")
  late String auth;
  @JsonKey(name: "subscriptionMillis")
  late int subscriptionMillis;
  @JsonKey(name: "priceDesc")
  late String? priceDesc;
  @JsonKey(name: "freeTrialPriceDesc")
  late String? freeTrialPriceDesc;
  @JsonKey(name: "freeTrialName")
  late String? freeTrialName;
  @JsonKey(name: "coefficient")
  late int coefficient;

  StoreItem({
    required this.id,
    required this.sort,
    required this.name,
    required this.appleGoodsId,
    required this.subscribable,
    required this.amount,
    required this.originalAmount,
    required this.auth,
    required this.subscriptionMillis,
    required this.priceDesc,
    required this.coefficient,
    this.freeTrialName,
    this.freeTrialPriceDesc,
  });

  get amountText => (amount / 100).toFormattedString(2);

  get originalAmountText => (originalAmount / 100).toFormattedString(2);

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