import 'package:electronic_assistant/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: "authValue")
  late int authValue;
  @JsonKey(name: "subscriptionMillis")
  late int subscriptionMillis;
  @JsonKey(name: "popular")
  late bool popular;
  @JsonKey(name: "content")
  late String content;
  @JsonKey(name: "itemDesc")
  late String itemDesc;

  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.authValue,
      required this.subscriptionMillis,
      required this.popular,
      required this.content,
      required this.itemDesc});

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

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

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