diff --git a/lib/src/prices/price_total_stats.dart b/lib/src/prices/price_total_stats.dart index aa8b1f3094..cbcf35929e 100644 --- a/lib/src/prices/price_total_stats.dart +++ b/lib/src/prices/price_total_stats.dart @@ -1,74 +1,75 @@ -import 'package:json_annotation/json_annotation.dart'; - -import '../interface/json_object.dart'; import '../utils/json_helper.dart'; -part 'price_total_stats.g.dart'; - /// Total stats for Prices. /// /// cf. `TotalStats` in https://prices.openfoodfacts.org/api/docs -@JsonSerializable() -class PriceTotalStats extends JsonObject { - @JsonKey(name: 'price_count') - int? priceCount; - - @JsonKey(name: 'price_type_product_code_count') - int? priceTypeProductCodeCount; - - @JsonKey(name: 'price_type_category_tag_count') - int? priceTypeCategoryTagCount; - - @JsonKey(name: 'product_count') - int? productCount; - - @JsonKey(name: 'product_with_price_count') - int? productWithPriceCount; - - @JsonKey(name: 'location_count') - int? locationCount; - - @JsonKey(name: 'location_with_price_count') - int? locationWithPriceCount; - - @JsonKey(name: 'location_type_osm_count') - int? locationTypeOsmCount; - - @JsonKey(name: 'location_type_online_count') - int? locationTypeOnlineCount; - - @JsonKey(name: 'proof_count') - int? proofCount; - - @JsonKey(name: 'proof_with_price_count') - int? proofWithPriceCount; - - @JsonKey(name: 'proof_type_price_tag_count') - int? proofTypePriceTagCount; - - @JsonKey(name: 'proof_type_receipt_count') - int? proofTypeReceiptCount; - - @JsonKey(name: 'proof_type_gdpr_request_count') - int? proofTypeGdprRequestCount; - - @JsonKey(name: 'proof_type_shop_import_count') - int? proofTypeShopImportCount; - - @JsonKey(name: 'user_count') - int? userCount; - - @JsonKey(name: 'user_with_price_count') - int? userWithPriceCount; - - @JsonKey(fromJson: JsonHelper.nullableStringTimestampToDate) - DateTime? updated; - - PriceTotalStats(); - - factory PriceTotalStats.fromJson(Map json) => - _$PriceTotalStatsFromJson(json); - - @override - Map toJson() => _$PriceTotalStatsToJson(this); +class PriceTotalStats { + final Map json; + + PriceTotalStats(this.json); + + factory PriceTotalStats.fromJson(Map json) { + return PriceTotalStats(json); + } + + int? get priceCount => getInt('price_count'); + int? get priceTypeProductCodeCount => getInt('price_type_product_code_count'); + int? get priceTypeCategoryTagCount => getInt('price_type_category_tag_count'); + int? get priceWithDiscountCount => getInt('price_with_discount_count'); + int? get priceCurrencyCount => getInt('price_currency_count'); + int? get priceYearCount => getInt('price_year_count'); + int? get priceLocationCountryCount => getInt('price_location_country_count'); + int? get priceKindCommunityCount => getInt('price_kind_community_count'); + int? get priceKindConsumptionCount => getInt('price_kind_consumption_count'); + int? get priceSourceWebCount => getInt('price_source_web_count'); + int? get priceSourceMobileCount => getInt('price_source_mobile_count'); + int? get priceSourceApiCount => getInt('price_source_api_count'); + int? get priceSourceOtherCount => getInt('price_source_other_count'); + int? get productCount => getInt('product_count'); + int? get productSourceOffCount => getInt('product_source_off_count'); + int? get productSourceObfCount => getInt('product_source_obf_count'); + int? get productSourceOpffCount => getInt('product_source_opff_count'); + int? get productSourceOpfCount => getInt('product_source_opf_count'); + int? get productWithPriceCount => getInt('product_with_price_count'); + int? get productSourceOffWithPriceCount => + getInt('product_source_off_with_price_count'); + int? get productSourceObfWithPriceCount => + getInt('product_source_obf_with_price_count'); + int? get productSourceOpffWithPriceCount => + getInt('product_source_opff_with_price_count'); + int? get productSourceOpfWithPriceCount => + getInt('product_source_opf_with_price_count'); + int? get locationCount => getInt('location_count'); + int? get locationWithPriceCount => getInt('location_with_price_count'); + int? get locationTypeOsmCount => getInt('location_type_osm_count'); + int? get locationTypeOnlineCount => getInt('location_type_online_count'); + int? get locationTypeOsmCountryCount => + getInt('location_type_osm_country_count'); + int? get proofCount => getInt('proof_count'); + int? get proofWithPriceCount => getInt('proof_with_price_count'); + int? get proofTypePriceTagCount => getInt('proof_type_price_tag_count'); + int? get proofTypeReceiptCount => getInt('proof_type_receipt_count'); + int? get proofTypeGdprRequestCount => getInt('proof_type_gdpr_request_count'); + int? get proofTypeShopImportCount => getInt('proof_type_shop_import_count'); + int? get proofKindCommunityCount => getInt('proof_kind_community_count'); + int? get proofKindConsumptionCount => getInt('proof_kind_consumption_count'); + int? get proofSourceWebCount => getInt('proof_source_web_count'); + int? get proofSourceMobileCount => getInt('proof_source_mobile_count'); + int? get proofSourceApiCount => getInt('proof_source_api_count'); + int? get proofSourceOtherCount => getInt('proof_source_other_count'); + int? get priceTagCount => getInt('price_tag_count'); + int? get priceTagStatusUnknownCount => + getInt('price_tag_status_unknown_count'); + int? get priceTagStatusLinkedToPriceCount => + getInt('price_tag_status_linked_to_price_count'); + int? get userCount => getInt('user_count'); + int? get userWithPriceCount => getInt('user_with_price_count'); + DateTime? get updated => getDateTime('updated'); + + int? getInt(String key) => json.containsKey(key) ? json[key] as int? : null; + + DateTime? getDateTime(String key) => + JsonHelper.nullableStringTimestampToDate(json[key]); + + Map toJson() => json; } diff --git a/lib/src/prices/price_total_stats.g.dart b/lib/src/prices/price_total_stats.g.dart deleted file mode 100644 index 200d2dfe30..0000000000 --- a/lib/src/prices/price_total_stats.g.dart +++ /dev/null @@ -1,60 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'price_total_stats.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -PriceTotalStats _$PriceTotalStatsFromJson(Map json) => - PriceTotalStats() - ..priceCount = (json['price_count'] as num?)?.toInt() - ..priceTypeProductCodeCount = - (json['price_type_product_code_count'] as num?)?.toInt() - ..priceTypeCategoryTagCount = - (json['price_type_category_tag_count'] as num?)?.toInt() - ..productCount = (json['product_count'] as num?)?.toInt() - ..productWithPriceCount = - (json['product_with_price_count'] as num?)?.toInt() - ..locationCount = (json['location_count'] as num?)?.toInt() - ..locationWithPriceCount = - (json['location_with_price_count'] as num?)?.toInt() - ..locationTypeOsmCount = - (json['location_type_osm_count'] as num?)?.toInt() - ..locationTypeOnlineCount = - (json['location_type_online_count'] as num?)?.toInt() - ..proofCount = (json['proof_count'] as num?)?.toInt() - ..proofWithPriceCount = (json['proof_with_price_count'] as num?)?.toInt() - ..proofTypePriceTagCount = - (json['proof_type_price_tag_count'] as num?)?.toInt() - ..proofTypeReceiptCount = - (json['proof_type_receipt_count'] as num?)?.toInt() - ..proofTypeGdprRequestCount = - (json['proof_type_gdpr_request_count'] as num?)?.toInt() - ..proofTypeShopImportCount = - (json['proof_type_shop_import_count'] as num?)?.toInt() - ..userCount = (json['user_count'] as num?)?.toInt() - ..userWithPriceCount = (json['user_with_price_count'] as num?)?.toInt() - ..updated = JsonHelper.nullableStringTimestampToDate(json['updated']); - -Map _$PriceTotalStatsToJson(PriceTotalStats instance) => - { - 'price_count': instance.priceCount, - 'price_type_product_code_count': instance.priceTypeProductCodeCount, - 'price_type_category_tag_count': instance.priceTypeCategoryTagCount, - 'product_count': instance.productCount, - 'product_with_price_count': instance.productWithPriceCount, - 'location_count': instance.locationCount, - 'location_with_price_count': instance.locationWithPriceCount, - 'location_type_osm_count': instance.locationTypeOsmCount, - 'location_type_online_count': instance.locationTypeOnlineCount, - 'proof_count': instance.proofCount, - 'proof_with_price_count': instance.proofWithPriceCount, - 'proof_type_price_tag_count': instance.proofTypePriceTagCount, - 'proof_type_receipt_count': instance.proofTypeReceiptCount, - 'proof_type_gdpr_request_count': instance.proofTypeGdprRequestCount, - 'proof_type_shop_import_count': instance.proofTypeShopImportCount, - 'user_count': instance.userCount, - 'user_with_price_count': instance.userWithPriceCount, - 'updated': instance.updated?.toIso8601String(), - };