2026-04-16 16:11:09 +08:00
|
|
|
enum ProductCode { newUserPack, basicPack, popularPack, premiumPack }
|
|
|
|
|
|
|
|
|
|
enum PackageType { starter, regular }
|
|
|
|
|
|
|
|
|
|
class PackageInfo {
|
|
|
|
|
const PackageInfo({
|
|
|
|
|
required this.productCode,
|
2026-04-28 10:45:29 +08:00
|
|
|
required this.appStoreProductId,
|
2026-04-16 16:11:09 +08:00
|
|
|
required this.type,
|
|
|
|
|
required this.price,
|
|
|
|
|
required this.credits,
|
|
|
|
|
required this.isStarter,
|
|
|
|
|
required this.starterEligible,
|
|
|
|
|
required this.sortOrder,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
final ProductCode productCode;
|
2026-04-28 10:45:29 +08:00
|
|
|
final String appStoreProductId;
|
2026-04-16 16:11:09 +08:00
|
|
|
final PackageType type;
|
|
|
|
|
final double price;
|
|
|
|
|
final int credits;
|
|
|
|
|
final bool isStarter;
|
|
|
|
|
final bool starterEligible;
|
|
|
|
|
final int sortOrder;
|
|
|
|
|
|
|
|
|
|
factory PackageInfo.fromJson(Map<String, dynamic> json) {
|
|
|
|
|
return PackageInfo(
|
|
|
|
|
productCode: _parseProductCode(json['productCode'] as String),
|
2026-04-28 10:45:29 +08:00
|
|
|
appStoreProductId: json['appStoreProductId'] as String,
|
2026-04-16 16:11:09 +08:00
|
|
|
type: json['type'] == 'starter'
|
|
|
|
|
? PackageType.starter
|
|
|
|
|
: PackageType.regular,
|
|
|
|
|
price: (json['price'] as num).toDouble(),
|
|
|
|
|
credits: json['credits'] as int,
|
|
|
|
|
isStarter: json['isStarter'] as bool,
|
|
|
|
|
starterEligible: json['starterEligible'] as bool,
|
|
|
|
|
sortOrder: json['sortOrder'] as int,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ProductCode _parseProductCode(String code) {
|
|
|
|
|
return switch (code) {
|
|
|
|
|
'new_user_pack' => ProductCode.newUserPack,
|
|
|
|
|
'basic_pack' => ProductCode.basicPack,
|
|
|
|
|
'popular_pack' => ProductCode.popularPack,
|
|
|
|
|
'premium_pack' => ProductCode.premiumPack,
|
|
|
|
|
_ => throw ArgumentError('Unknown product code: $code'),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String get priceDisplay => '\$${price.toStringAsFixed(2)}';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PackagesResult {
|
|
|
|
|
const PackagesResult({
|
|
|
|
|
required this.region,
|
|
|
|
|
required this.currency,
|
|
|
|
|
required this.packages,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
final String region;
|
|
|
|
|
final String currency;
|
|
|
|
|
final List<PackageInfo> packages;
|
|
|
|
|
|
|
|
|
|
factory PackagesResult.fromJson(Map<String, dynamic> json) {
|
|
|
|
|
return PackagesResult(
|
|
|
|
|
region: json['region'] as String,
|
|
|
|
|
currency: json['currency'] as String,
|
|
|
|
|
packages: (json['packages'] as List<dynamic>)
|
|
|
|
|
.map((e) => PackageInfo.fromJson(e as Map<String, dynamic>))
|
|
|
|
|
.toList(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|