diff --git a/mnemo_cards_backend b/mnemo_cards_backend deleted file mode 160000 index 76d5f8e..0000000 --- a/mnemo_cards_backend +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 76d5f8efdb7e71bcb375f3e4c80eca666ecb9aa3 diff --git a/mnemo_cards_common b/mnemo_cards_common deleted file mode 160000 index 22e65dc..0000000 --- a/mnemo_cards_common +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 22e65dcc3650f220eeacbd94c866f0e37b0a94a0 diff --git a/mnemo_cards_common/CHANGELOG.md b/mnemo_cards_common/CHANGELOG.md new file mode 100644 index 0000000..41cc7d8 --- /dev/null +++ b/mnemo_cards_common/CHANGELOG.md @@ -0,0 +1,3 @@ +## 0.0.1 + +* TODO: Describe initial release. diff --git a/mnemo_cards_common/LICENSE b/mnemo_cards_common/LICENSE new file mode 100644 index 0000000..ba75c69 --- /dev/null +++ b/mnemo_cards_common/LICENSE @@ -0,0 +1 @@ +TODO: Add your license here. diff --git a/mnemo_cards_common/README.md b/mnemo_cards_common/README.md new file mode 100644 index 0000000..02fe8ec --- /dev/null +++ b/mnemo_cards_common/README.md @@ -0,0 +1,39 @@ + + +TODO: Put a short description of the package here that helps potential users +know whether this package might be useful for them. + +## Features + +TODO: List what your package can do. Maybe include images, gifs, or videos. + +## Getting started + +TODO: List prerequisites and provide or point to information on how to +start using the package. + +## Usage + +TODO: Include short and useful examples for package users. Add longer examples +to `/example` folder. + +```dart +const like = 'sample'; +``` + +## Additional information + +TODO: Tell users more about the package: where to find more information, how to +contribute to the package, how to file issues, what response they can expect +from the package authors, and more. diff --git a/mnemo_cards_common/analysis_options.yaml b/mnemo_cards_common/analysis_options.yaml new file mode 100644 index 0000000..a5744c1 --- /dev/null +++ b/mnemo_cards_common/analysis_options.yaml @@ -0,0 +1,4 @@ +include: package:flutter_lints/flutter.yaml + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/mnemo_cards_common/codegen.sh b/mnemo_cards_common/codegen.sh new file mode 100644 index 0000000..29b3520 --- /dev/null +++ b/mnemo_cards_common/codegen.sh @@ -0,0 +1,2 @@ +#!/bin/bash +dart run build_runner build --delete-conflicting-outputs diff --git a/mnemo_cards_common/food_tests/eda_test_ne_znau_gramatica.json b/mnemo_cards_common/food_tests/eda_test_ne_znau_gramatica.json new file mode 100644 index 0000000..9a62b82 --- /dev/null +++ b/mnemo_cards_common/food_tests/eda_test_ne_znau_gramatica.json @@ -0,0 +1,61 @@ +{ + "pack": "3", + "data": [ + { + "es": "zumo de mora", + "ru": "сок из ежевики" + }, + { + "es": "zumo de col", + "ru": "сок из капусты" + }, + { + "es": "zumo de zanahoria", + "ru": "морковный сок" + }, + { + "es": "zumo de sandía", + "ru": "арбузный сок" + }, + { + "es": "zumo de fresa", + "ru": "клубничный сок" + }, + { + "es": "zumo de piña", + "ru": "ананасовый сок" + }, + { + "es": "zumo de calabaza", + "ru": "тыквенный сок" + }, + { + "es": "pastel de queso", + "ru": "чизкейк" + }, + { + "es": "pastel de zanahoria", + "ru": "морковный торт" + }, + { + "es": "pastel de fresa", + "ru": "клубничный торт" + }, + { + "es": "pastel de piña", + "ru": "ананасовый торт" + }, + { + "es": "pastel de calabaza", + "ru": "тыквенный торт" + }, + { + "es": "pastel de plátano", + "ru": "банановый торт" + }, + { + "es": "pastel de higo", + "ru": "торт с инжиром" + } + ] +} \ No newline at end of file diff --git a/mnemo_cards_common/lib/mnemo_cards_common.dart b/mnemo_cards_common/lib/mnemo_cards_common.dart new file mode 100644 index 0000000..ed8a2b3 --- /dev/null +++ b/mnemo_cards_common/lib/mnemo_cards_common.dart @@ -0,0 +1,57 @@ +library mnemo_cards_common; + +export 'src/dtos/packs/card_pack_action.dart'; +export 'src/dtos/packs/card_pack_dto.dart'; +export 'src/dtos/packs/edit_card_pack_dto.dart'; +export 'src/dtos/packs/card_pack_buy_dto.dart'; +export 'src/dtos/packs/card_pack_loading_dto.dart'; +export 'src/dtos/packs/card_pack_preview_dto.dart'; +export 'src/dtos/packs/pack_tip.dart'; +export 'src/dtos/packs/get_card_pack_response.dart'; +export 'src/dtos/game_card_dto.dart'; + +export 'src/dtos/payment/export.dart'; + +export 'src/dtos/promo_codes/promo_codes_campaign_dto.dart'; +export 'src/dtos/discounts/discount_campaign_dto.dart'; +export 'src/dtos/discounts/discount_dto.dart'; + +export 'src/dtos/user/user_dto.dart'; +export 'src/dtos/user/data/user_data_dto.dart'; +export 'src/dtos/user/data/word_statistics_dto.dart'; +export 'src/dtos/user/data/all_words_statistics_dto.dart'; +export 'src/dtos/game_tests/test_statistics_dto.dart'; +export 'src/dtos/user/data/all_tests_statistics_dto.dart'; +export 'src/dtos/user/promo_code_dto.dart'; +export 'src/dtos/user/settings/user_settings_dto.dart'; +export 'src/dtos/user/enums.dart'; + +// NEW: Extended statistics DTOs +export 'src/dtos/user/data/pack_progress_dto.dart'; +export 'src/dtos/user/achievement_dto.dart'; +export 'src/dtos/user/data/detailed_word_statistics_dto.dart'; +export 'src/dtos/user/study_session_dto.dart'; + +export 'src/dtos/games/game_dto.dart'; + +export 'src/dtos/game_tests/test_bodies/input_buttons_test_question_body.dart'; +export 'src/dtos/game_tests/test_bodies/simple_test_question.dart'; +export 'src/dtos/game_tests/test_bodies/abstract_test_question.dart'; + +export 'src/dtos/subscription/subscription_plan_admin_dto.dart'; +export 'src/dtos/subscription/subscription_plan_dto.dart'; +export 'src/dtos/subscription/subscription_features.dart'; +export 'src/dtos/subscription/subscription_plan_ui_dto.dart'; + +export 'src/dtos/game_tests/test.dart'; +export 'src/dtos/game_tests/test_button.dart'; +export 'src/dtos/game_tests/test_question_type.dart'; + +export 'src/dtos/items/items.dart'; + +export 'src/utils/utils.dart'; +export 'src/utils/iterable_helper.dart'; +export 'src/utils/token_generator.dart'; +export 'src/app_headers.dart'; + +export 'src/deeplinks/export.dart'; diff --git a/mnemo_cards_common/lib/src/app_headers.dart b/mnemo_cards_common/lib/src/app_headers.dart new file mode 100644 index 0000000..99bf721 --- /dev/null +++ b/mnemo_cards_common/lib/src/app_headers.dart @@ -0,0 +1,5 @@ +class AppHeaders { + static const String userToken = 'user_token'; + static const String requestToken = 'request_token'; + static const String appVersion = 'app_version'; +} \ No newline at end of file diff --git a/mnemo_cards_common/lib/src/deeplinks/deeplink.dart b/mnemo_cards_common/lib/src/deeplinks/deeplink.dart new file mode 100644 index 0000000..7d878fa --- /dev/null +++ b/mnemo_cards_common/lib/src/deeplinks/deeplink.dart @@ -0,0 +1,16 @@ +import 'package:mnemo_cards_common/mnemo_cards_common.dart'; + +abstract mixin class MnemoCardsDeeplink { + String get host; + + String get path; + + Map? get queryParameters; + + Uri get uri => Uri( + scheme: 'mnemocards', + host: host, + path: path.notEmptyOrNull, + queryParameters: queryParameters, + ); +} diff --git a/mnemo_cards_common/lib/src/deeplinks/export.dart b/mnemo_cards_common/lib/src/deeplinks/export.dart new file mode 100644 index 0000000..c085479 --- /dev/null +++ b/mnemo_cards_common/lib/src/deeplinks/export.dart @@ -0,0 +1,5 @@ +export 'purchase_check.dart'; +export 'purchase_init.dart'; +export 'subscription_open.dart'; +export 'product_for_ad.dart'; +export 'deeplink.dart'; diff --git a/mnemo_cards_common/lib/src/deeplinks/product_for_ad.dart b/mnemo_cards_common/lib/src/deeplinks/product_for_ad.dart new file mode 100644 index 0000000..a0f847a --- /dev/null +++ b/mnemo_cards_common/lib/src/deeplinks/product_for_ad.dart @@ -0,0 +1,31 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:mnemo_cards_common/src/deeplinks/deeplink.dart'; + +import '../dtos/payment/export.dart'; + +class ProductForAdDeeplink with MnemoCardsDeeplink { + final MnemoCardsProductDto product; + final String key; + + static const deeplinkPath = 'open'; + + ProductForAdDeeplink(this.product, this.key); + + @override + String get host => 'ad'; + + @override + String get path => deeplinkPath; + + @override + Map? get queryParameters => { + 'key': key, + 'id': product.id, + 'type': product.toJson()['type'], + }; + + factory ProductForAdDeeplink.parse(Uri uri) => ProductForAdDeeplink( + MnemoCardsProductDto.fromJson(uri.queryParameters), + uri.queryParameters['key'] as String, + ); +} diff --git a/mnemo_cards_common/lib/src/deeplinks/purchase_check.dart b/mnemo_cards_common/lib/src/deeplinks/purchase_check.dart new file mode 100644 index 0000000..aa59114 --- /dev/null +++ b/mnemo_cards_common/lib/src/deeplinks/purchase_check.dart @@ -0,0 +1,45 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:mnemo_cards_common/src/deeplinks/deeplink.dart'; + +import '../dtos/payment/export.dart'; + +part 'purchase_check.g.dart'; + +@JsonSerializable() +class PurchaseCheckDeeplink with MnemoCardsDeeplink { + final String id; + + @JsonKey( + fromJson: MnemoCardsProductType.fromName, + toJson: MnemoCardsProductType.toName, + ) + final MnemoCardsProductType productType; + + // For yookassa - same as payment model id + final String token; + + @JsonKey(unknownEnumValue: PaymentSystem.unknown) + final PaymentSystem paymentSystem; + + static const deeplinkPath = 'check'; + + PurchaseCheckDeeplink({ + required this.id, + required this.productType, + required this.token, + required this.paymentSystem, + }); + + @override + String get host => 'purchase'; + + @override + String get path => deeplinkPath; + + @override + Map? get queryParameters => + _$PurchaseCheckDeeplinkToJson(this); + + factory PurchaseCheckDeeplink.parse(Uri uri) => + _$PurchaseCheckDeeplinkFromJson(uri.queryParameters); +} diff --git a/mnemo_cards_common/lib/src/deeplinks/purchase_check.g.dart b/mnemo_cards_common/lib/src/deeplinks/purchase_check.g.dart new file mode 100644 index 0000000..063be28 --- /dev/null +++ b/mnemo_cards_common/lib/src/deeplinks/purchase_check.g.dart @@ -0,0 +1,37 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'purchase_check.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +PurchaseCheckDeeplink _$PurchaseCheckDeeplinkFromJson( + Map json) => + PurchaseCheckDeeplink( + id: json['id'] as String, + productType: + MnemoCardsProductType.fromName(json['productType'] as String), + token: json['token'] as String, + paymentSystem: $enumDecode(_$PaymentSystemEnumMap, json['paymentSystem'], + unknownValue: PaymentSystem.unknown), + ); + +Map _$PurchaseCheckDeeplinkToJson( + PurchaseCheckDeeplink instance) => + { + 'id': instance.id, + 'productType': MnemoCardsProductType.toName(instance.productType), + 'token': instance.token, + 'paymentSystem': _$PaymentSystemEnumMap[instance.paymentSystem]!, + }; + +const _$PaymentSystemEnumMap = { + PaymentSystem.google: 'google', + PaymentSystem.apple: 'apple', + PaymentSystem.rustore: 'rustore', + PaymentSystem.yookassa: 'yookassa', + PaymentSystem.promoCode: 'promoCode', + PaymentSystem.adView: 'adView', + PaymentSystem.unknown: 'unknown', +}; diff --git a/mnemo_cards_common/lib/src/deeplinks/purchase_init.dart b/mnemo_cards_common/lib/src/deeplinks/purchase_init.dart new file mode 100644 index 0000000..05afc72 --- /dev/null +++ b/mnemo_cards_common/lib/src/deeplinks/purchase_init.dart @@ -0,0 +1,45 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:mnemo_cards_common/src/deeplinks/deeplink.dart'; + +import '../dtos/payment/export.dart'; + +part 'purchase_init.g.dart'; + +@JsonSerializable() +class PurchaseInitDeeplink with MnemoCardsDeeplink { + final String id; + + @JsonKey( + fromJson: MnemoCardsProductType.fromName, + toJson: MnemoCardsProductType.toName, + ) + final MnemoCardsProductType productType; + final String paymentId; + + @JsonKey(unknownEnumValue: PaymentSystem.unknown) + final PaymentSystem paymentSystem; + final String? source; + + static const deeplinkPath = 'init'; + + PurchaseInitDeeplink({ + required this.id, + required this.productType, + required this.paymentId, + required this.paymentSystem, + this.source, + }); + + @override + String get host => 'purchase'; + + @override + String get path => deeplinkPath; + + @override + Map? get queryParameters => + _$PurchaseInitDeeplinkToJson(this); + + factory PurchaseInitDeeplink.parse(Uri uri) => + _$PurchaseInitDeeplinkFromJson(uri.queryParameters); +} diff --git a/mnemo_cards_common/lib/src/deeplinks/purchase_init.g.dart b/mnemo_cards_common/lib/src/deeplinks/purchase_init.g.dart new file mode 100644 index 0000000..7bb4232 --- /dev/null +++ b/mnemo_cards_common/lib/src/deeplinks/purchase_init.g.dart @@ -0,0 +1,39 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'purchase_init.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +PurchaseInitDeeplink _$PurchaseInitDeeplinkFromJson( + Map json) => + PurchaseInitDeeplink( + id: json['id'] as String, + productType: + MnemoCardsProductType.fromName(json['productType'] as String), + paymentId: json['paymentId'] as String, + paymentSystem: $enumDecode(_$PaymentSystemEnumMap, json['paymentSystem'], + unknownValue: PaymentSystem.unknown), + source: json['source'] as String?, + ); + +Map _$PurchaseInitDeeplinkToJson( + PurchaseInitDeeplink instance) => + { + 'id': instance.id, + 'productType': MnemoCardsProductType.toName(instance.productType), + 'paymentId': instance.paymentId, + 'paymentSystem': _$PaymentSystemEnumMap[instance.paymentSystem]!, + 'source': instance.source, + }; + +const _$PaymentSystemEnumMap = { + PaymentSystem.google: 'google', + PaymentSystem.apple: 'apple', + PaymentSystem.rustore: 'rustore', + PaymentSystem.yookassa: 'yookassa', + PaymentSystem.promoCode: 'promoCode', + PaymentSystem.adView: 'adView', + PaymentSystem.unknown: 'unknown', +}; diff --git a/mnemo_cards_common/lib/src/deeplinks/subscription_open.dart b/mnemo_cards_common/lib/src/deeplinks/subscription_open.dart new file mode 100644 index 0000000..a61b6c8 --- /dev/null +++ b/mnemo_cards_common/lib/src/deeplinks/subscription_open.dart @@ -0,0 +1,26 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:mnemo_cards_common/src/deeplinks/deeplink.dart'; + + +part 'subscription_open.g.dart'; + +@JsonSerializable() +class SubscriptionOpenDeeplink with MnemoCardsDeeplink { + + static const deeplinkPath = 'open'; + + SubscriptionOpenDeeplink(); + + @override + String get host => 'subscription'; + + @override + String get path => deeplinkPath; + + @override + Map? get queryParameters => + _$SubscriptionOpenDeeplinkToJson(this); + + factory SubscriptionOpenDeeplink.parse(Uri uri) => + _$SubscriptionOpenDeeplinkFromJson(uri.queryParameters); +} diff --git a/mnemo_cards_common/lib/src/deeplinks/subscription_open.g.dart b/mnemo_cards_common/lib/src/deeplinks/subscription_open.g.dart new file mode 100644 index 0000000..9ba2ca4 --- /dev/null +++ b/mnemo_cards_common/lib/src/deeplinks/subscription_open.g.dart @@ -0,0 +1,15 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'subscription_open.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SubscriptionOpenDeeplink _$SubscriptionOpenDeeplinkFromJson( + Map json) => + SubscriptionOpenDeeplink(); + +Map _$SubscriptionOpenDeeplinkToJson( + SubscriptionOpenDeeplink instance) => + {}; diff --git a/mnemo_cards_common/lib/src/dtos/discounts/discount_campaign_dto.dart b/mnemo_cards_common/lib/src/dtos/discounts/discount_campaign_dto.dart new file mode 100644 index 0000000..d6f9daf --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/discounts/discount_campaign_dto.dart @@ -0,0 +1,40 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:mnemo_cards_common/src/dtos/discounts/discount_dto.dart'; + + +part 'discount_campaign_dto.g.dart'; + +@JsonSerializable() +@CopyWith() +class DiscountCampaignDto { + final int? id; + final DateTime start; + final DateTime finish; + final DiscountCampaignStatus status; + final String? name; + final List tags; + final List discounts; + + const DiscountCampaignDto({ + required this.start, + required this.finish, + required this.status, + required this.tags, + required this.discounts, + this.name, + this.id, + }); + + factory DiscountCampaignDto.fromJson(Map json) => + _$DiscountCampaignDtoFromJson(json); + + Map toJson() => _$DiscountCampaignDtoToJson(this); +} + +enum DiscountCampaignStatus { + created, + active, + expired, + disabled, +} diff --git a/mnemo_cards_common/lib/src/dtos/discounts/discount_campaign_dto.g.dart b/mnemo_cards_common/lib/src/dtos/discounts/discount_campaign_dto.g.dart new file mode 100644 index 0000000..a6cce05 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/discounts/discount_campaign_dto.g.dart @@ -0,0 +1,161 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'discount_campaign_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$DiscountCampaignDtoCWProxy { + DiscountCampaignDto start(DateTime start); + + DiscountCampaignDto finish(DateTime finish); + + DiscountCampaignDto status(DiscountCampaignStatus status); + + DiscountCampaignDto tags(List tags); + + DiscountCampaignDto discounts(List discounts); + + DiscountCampaignDto name(String? name); + + DiscountCampaignDto id(int? id); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `DiscountCampaignDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// DiscountCampaignDto(...).copyWith(id: 12, name: "My name") + /// ```` + DiscountCampaignDto call({ + DateTime? start, + DateTime? finish, + DiscountCampaignStatus? status, + List? tags, + List? discounts, + String? name, + int? id, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfDiscountCampaignDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfDiscountCampaignDto.copyWith.fieldName(...)` +class _$DiscountCampaignDtoCWProxyImpl implements _$DiscountCampaignDtoCWProxy { + const _$DiscountCampaignDtoCWProxyImpl(this._value); + + final DiscountCampaignDto _value; + + @override + DiscountCampaignDto start(DateTime start) => this(start: start); + + @override + DiscountCampaignDto finish(DateTime finish) => this(finish: finish); + + @override + DiscountCampaignDto status(DiscountCampaignStatus status) => + this(status: status); + + @override + DiscountCampaignDto tags(List tags) => this(tags: tags); + + @override + DiscountCampaignDto discounts(List discounts) => + this(discounts: discounts); + + @override + DiscountCampaignDto name(String? name) => this(name: name); + + @override + DiscountCampaignDto id(int? id) => this(id: id); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `DiscountCampaignDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// DiscountCampaignDto(...).copyWith(id: 12, name: "My name") + /// ```` + DiscountCampaignDto call({ + Object? start = const $CopyWithPlaceholder(), + Object? finish = const $CopyWithPlaceholder(), + Object? status = const $CopyWithPlaceholder(), + Object? tags = const $CopyWithPlaceholder(), + Object? discounts = const $CopyWithPlaceholder(), + Object? name = const $CopyWithPlaceholder(), + Object? id = const $CopyWithPlaceholder(), + }) { + return DiscountCampaignDto( + start: start == const $CopyWithPlaceholder() || start == null + ? _value.start + // ignore: cast_nullable_to_non_nullable + : start as DateTime, + finish: finish == const $CopyWithPlaceholder() || finish == null + ? _value.finish + // ignore: cast_nullable_to_non_nullable + : finish as DateTime, + status: status == const $CopyWithPlaceholder() || status == null + ? _value.status + // ignore: cast_nullable_to_non_nullable + : status as DiscountCampaignStatus, + tags: tags == const $CopyWithPlaceholder() || tags == null + ? _value.tags + // ignore: cast_nullable_to_non_nullable + : tags as List, + discounts: discounts == const $CopyWithPlaceholder() || discounts == null + ? _value.discounts + // ignore: cast_nullable_to_non_nullable + : discounts as List, + name: name == const $CopyWithPlaceholder() + ? _value.name + // ignore: cast_nullable_to_non_nullable + : name as String?, + id: id == const $CopyWithPlaceholder() + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as int?, + ); + } +} + +extension $DiscountCampaignDtoCopyWith on DiscountCampaignDto { + /// Returns a callable class that can be used as follows: `instanceOfDiscountCampaignDto.copyWith(...)` or like so:`instanceOfDiscountCampaignDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$DiscountCampaignDtoCWProxy get copyWith => + _$DiscountCampaignDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +DiscountCampaignDto _$DiscountCampaignDtoFromJson(Map json) => + DiscountCampaignDto( + start: DateTime.parse(json['start'] as String), + finish: DateTime.parse(json['finish'] as String), + status: $enumDecode(_$DiscountCampaignStatusEnumMap, json['status']), + tags: (json['tags'] as List).map((e) => e as String).toList(), + discounts: (json['discounts'] as List) + .map((e) => DiscountDto.fromJson(e as Map)) + .toList(), + name: json['name'] as String?, + id: json['id'] as int?, + ); + +Map _$DiscountCampaignDtoToJson( + DiscountCampaignDto instance) => + { + 'id': instance.id, + 'start': instance.start.toIso8601String(), + 'finish': instance.finish.toIso8601String(), + 'status': _$DiscountCampaignStatusEnumMap[instance.status]!, + 'name': instance.name, + 'tags': instance.tags, + 'discounts': instance.discounts, + }; + +const _$DiscountCampaignStatusEnumMap = { + DiscountCampaignStatus.created: 'created', + DiscountCampaignStatus.active: 'active', + DiscountCampaignStatus.expired: 'expired', + DiscountCampaignStatus.disabled: 'disabled', +}; diff --git a/mnemo_cards_common/lib/src/dtos/discounts/discount_dto.dart b/mnemo_cards_common/lib/src/dtos/discounts/discount_dto.dart new file mode 100644 index 0000000..7f2f89a --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/discounts/discount_dto.dart @@ -0,0 +1,28 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; + +import '../payment/export.dart'; + +part 'discount_dto.g.dart'; + +@JsonSerializable() +@CopyWith() +class DiscountDto implements MnemoCardsProductDto { + String? id; + final double discountPercent; // 0 - 100 + final List products; + + DiscountDto({ + required this.discountPercent, + required this.products, + this.id, + }); + + factory DiscountDto.fromJson(Map json) => + _$DiscountDtoFromJson(json); + + Map toJson() => _$DiscountDtoToJson(this); + + @override + MnemoCardsProductType get type => MnemoCardsProductType.discount; +} diff --git a/mnemo_cards_common/lib/src/dtos/discounts/discount_dto.g.dart b/mnemo_cards_common/lib/src/dtos/discounts/discount_dto.g.dart new file mode 100644 index 0000000..3b62c83 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/discounts/discount_dto.g.dart @@ -0,0 +1,100 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'discount_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$DiscountDtoCWProxy { + DiscountDto discountPercent(double discountPercent); + + DiscountDto products(List products); + + DiscountDto id(String? id); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `DiscountDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// DiscountDto(...).copyWith(id: 12, name: "My name") + /// ```` + DiscountDto call({ + double? discountPercent, + List? products, + String? id, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfDiscountDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfDiscountDto.copyWith.fieldName(...)` +class _$DiscountDtoCWProxyImpl implements _$DiscountDtoCWProxy { + const _$DiscountDtoCWProxyImpl(this._value); + + final DiscountDto _value; + + @override + DiscountDto discountPercent(double discountPercent) => + this(discountPercent: discountPercent); + + @override + DiscountDto products(List products) => + this(products: products); + + @override + DiscountDto id(String? id) => this(id: id); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `DiscountDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// DiscountDto(...).copyWith(id: 12, name: "My name") + /// ```` + DiscountDto call({ + Object? discountPercent = const $CopyWithPlaceholder(), + Object? products = const $CopyWithPlaceholder(), + Object? id = const $CopyWithPlaceholder(), + }) { + return DiscountDto( + discountPercent: discountPercent == const $CopyWithPlaceholder() || + discountPercent == null + ? _value.discountPercent + // ignore: cast_nullable_to_non_nullable + : discountPercent as double, + products: products == const $CopyWithPlaceholder() || products == null + ? _value.products + // ignore: cast_nullable_to_non_nullable + : products as List, + id: id == const $CopyWithPlaceholder() + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as String?, + ); + } +} + +extension $DiscountDtoCopyWith on DiscountDto { + /// Returns a callable class that can be used as follows: `instanceOfDiscountDto.copyWith(...)` or like so:`instanceOfDiscountDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$DiscountDtoCWProxy get copyWith => _$DiscountDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +DiscountDto _$DiscountDtoFromJson(Map json) => DiscountDto( + discountPercent: (json['discountPercent'] as num).toDouble(), + products: (json['products'] as List) + .map((e) => MnemoCardsProductDto.fromJson(e as Map)) + .toList(), + id: json['id'] as String?, + ); + +Map _$DiscountDtoToJson(DiscountDto instance) => + { + 'id': instance.id, + 'discountPercent': instance.discountPercent, + 'products': instance.products, + }; diff --git a/mnemo_cards_common/lib/src/dtos/game_card_dto.dart b/mnemo_cards_common/lib/src/dtos/game_card_dto.dart new file mode 100644 index 0000000..a24ab8c --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/game_card_dto.dart @@ -0,0 +1,35 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; + +part 'game_card_dto.g.dart'; + +@JsonSerializable() +@CopyWith() +class GameCardDto { + final int id; + final String? image; + final String? mnemo; + final String? original; + final String? translation; + final String? transcription; + final String? imageBack; + final String? transcriptionMnemo; + final String? back; + + const GameCardDto({ + required this.id, + required this.mnemo, + required this.original, + required this.translation, + required this.transcription, + this.transcriptionMnemo, + this.image, + this.imageBack, + this.back, + }); + + factory GameCardDto.fromJson(Map json) => + _$GameCardDtoFromJson(json); + + Map toJson() => _$GameCardDtoToJson(this); +} diff --git a/mnemo_cards_common/lib/src/dtos/game_card_dto.g.dart b/mnemo_cards_common/lib/src/dtos/game_card_dto.g.dart new file mode 100644 index 0000000..5d29345 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/game_card_dto.g.dart @@ -0,0 +1,176 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'game_card_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$GameCardDtoCWProxy { + GameCardDto id(int id); + + GameCardDto mnemo(String? mnemo); + + GameCardDto original(String? original); + + GameCardDto translation(String? translation); + + GameCardDto transcription(String? transcription); + + GameCardDto transcriptionMnemo(String? transcriptionMnemo); + + GameCardDto image(String? image); + + GameCardDto imageBack(String? imageBack); + + GameCardDto back(String? back); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `GameCardDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// GameCardDto(...).copyWith(id: 12, name: "My name") + /// ```` + GameCardDto call({ + int? id, + String? mnemo, + String? original, + String? translation, + String? transcription, + String? transcriptionMnemo, + String? image, + String? imageBack, + String? back, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfGameCardDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfGameCardDto.copyWith.fieldName(...)` +class _$GameCardDtoCWProxyImpl implements _$GameCardDtoCWProxy { + const _$GameCardDtoCWProxyImpl(this._value); + + final GameCardDto _value; + + @override + GameCardDto id(int id) => this(id: id); + + @override + GameCardDto mnemo(String? mnemo) => this(mnemo: mnemo); + + @override + GameCardDto original(String? original) => this(original: original); + + @override + GameCardDto translation(String? translation) => + this(translation: translation); + + @override + GameCardDto transcription(String? transcription) => + this(transcription: transcription); + + @override + GameCardDto transcriptionMnemo(String? transcriptionMnemo) => + this(transcriptionMnemo: transcriptionMnemo); + + @override + GameCardDto image(String? image) => this(image: image); + + @override + GameCardDto imageBack(String? imageBack) => this(imageBack: imageBack); + + @override + GameCardDto back(String? back) => this(back: back); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `GameCardDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// GameCardDto(...).copyWith(id: 12, name: "My name") + /// ```` + GameCardDto call({ + Object? id = const $CopyWithPlaceholder(), + Object? mnemo = const $CopyWithPlaceholder(), + Object? original = const $CopyWithPlaceholder(), + Object? translation = const $CopyWithPlaceholder(), + Object? transcription = const $CopyWithPlaceholder(), + Object? transcriptionMnemo = const $CopyWithPlaceholder(), + Object? image = const $CopyWithPlaceholder(), + Object? imageBack = const $CopyWithPlaceholder(), + Object? back = const $CopyWithPlaceholder(), + }) { + return GameCardDto( + id: id == const $CopyWithPlaceholder() || id == null + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as int, + mnemo: mnemo == const $CopyWithPlaceholder() + ? _value.mnemo + // ignore: cast_nullable_to_non_nullable + : mnemo as String?, + original: original == const $CopyWithPlaceholder() + ? _value.original + // ignore: cast_nullable_to_non_nullable + : original as String?, + translation: translation == const $CopyWithPlaceholder() + ? _value.translation + // ignore: cast_nullable_to_non_nullable + : translation as String?, + transcription: transcription == const $CopyWithPlaceholder() + ? _value.transcription + // ignore: cast_nullable_to_non_nullable + : transcription as String?, + transcriptionMnemo: transcriptionMnemo == const $CopyWithPlaceholder() + ? _value.transcriptionMnemo + // ignore: cast_nullable_to_non_nullable + : transcriptionMnemo as String?, + image: image == const $CopyWithPlaceholder() + ? _value.image + // ignore: cast_nullable_to_non_nullable + : image as String?, + imageBack: imageBack == const $CopyWithPlaceholder() + ? _value.imageBack + // ignore: cast_nullable_to_non_nullable + : imageBack as String?, + back: back == const $CopyWithPlaceholder() + ? _value.back + // ignore: cast_nullable_to_non_nullable + : back as String?, + ); + } +} + +extension $GameCardDtoCopyWith on GameCardDto { + /// Returns a callable class that can be used as follows: `instanceOfGameCardDto.copyWith(...)` or like so:`instanceOfGameCardDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$GameCardDtoCWProxy get copyWith => _$GameCardDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +GameCardDto _$GameCardDtoFromJson(Map json) => GameCardDto( + id: json['id'] as int, + mnemo: json['mnemo'] as String?, + original: json['original'] as String?, + translation: json['translation'] as String?, + transcription: json['transcription'] as String?, + transcriptionMnemo: json['transcriptionMnemo'] as String?, + image: json['image'] as String?, + imageBack: json['imageBack'] as String?, + back: json['back'] as String?, + ); + +Map _$GameCardDtoToJson(GameCardDto instance) => + { + 'id': instance.id, + 'image': instance.image, + 'mnemo': instance.mnemo, + 'original': instance.original, + 'translation': instance.translation, + 'transcription': instance.transcription, + 'imageBack': instance.imageBack, + 'transcriptionMnemo': instance.transcriptionMnemo, + 'back': instance.back, + }; diff --git a/mnemo_cards_common/lib/src/dtos/game_tests/test.dart b/mnemo_cards_common/lib/src/dtos/game_tests/test.dart new file mode 100644 index 0000000..14d1de5 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/game_tests/test.dart @@ -0,0 +1,50 @@ +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:mnemo_cards_common/mnemo_cards_common.dart'; + +part 'test.g.dart'; + +@JsonSerializable() +@CopyWith() +class TestDto { + final List questions; + final String name; + final String? color; + final String? cover; + final String? version; + final String? time; + final String? timeSubtitle; + final TestStatisticsDto? statistics; + + String? id; + + TestDto({ + this.id, + required this.questions, + required this.name, + this.time, + this.timeSubtitle, + this.color, + this.cover, + this.statistics, + this.version, + }); + + factory TestDto.fromJson(Map json) => + _$TestDtoFromJson(json); + + Map toJson() => _$TestDtoToJson(this); + + @override + int get hashCode => version.hashCode ^ statistics.hashCode ^ id.hashCode; + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is TestDto && + other.statistics == statistics && + other.version == version && + other.id == id; + } +} diff --git a/mnemo_cards_common/lib/src/dtos/game_tests/test.g.dart b/mnemo_cards_common/lib/src/dtos/game_tests/test.g.dart new file mode 100644 index 0000000..38aef5f --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/game_tests/test.g.dart @@ -0,0 +1,180 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'test.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$TestDtoCWProxy { + TestDto id(String? id); + + TestDto questions(List questions); + + TestDto name(String name); + + TestDto time(String? time); + + TestDto timeSubtitle(String? timeSubtitle); + + TestDto color(String? color); + + TestDto cover(String? cover); + + TestDto statistics(TestStatisticsDto? statistics); + + TestDto version(String? version); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TestDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// TestDto(...).copyWith(id: 12, name: "My name") + /// ```` + TestDto call({ + String? id, + List? questions, + String? name, + String? time, + String? timeSubtitle, + String? color, + String? cover, + TestStatisticsDto? statistics, + String? version, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfTestDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfTestDto.copyWith.fieldName(...)` +class _$TestDtoCWProxyImpl implements _$TestDtoCWProxy { + const _$TestDtoCWProxyImpl(this._value); + + final TestDto _value; + + @override + TestDto id(String? id) => this(id: id); + + @override + TestDto questions(List questions) => + this(questions: questions); + + @override + TestDto name(String name) => this(name: name); + + @override + TestDto time(String? time) => this(time: time); + + @override + TestDto timeSubtitle(String? timeSubtitle) => + this(timeSubtitle: timeSubtitle); + + @override + TestDto color(String? color) => this(color: color); + + @override + TestDto cover(String? cover) => this(cover: cover); + + @override + TestDto statistics(TestStatisticsDto? statistics) => + this(statistics: statistics); + + @override + TestDto version(String? version) => this(version: version); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TestDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// TestDto(...).copyWith(id: 12, name: "My name") + /// ```` + TestDto call({ + Object? id = const $CopyWithPlaceholder(), + Object? questions = const $CopyWithPlaceholder(), + Object? name = const $CopyWithPlaceholder(), + Object? time = const $CopyWithPlaceholder(), + Object? timeSubtitle = const $CopyWithPlaceholder(), + Object? color = const $CopyWithPlaceholder(), + Object? cover = const $CopyWithPlaceholder(), + Object? statistics = const $CopyWithPlaceholder(), + Object? version = const $CopyWithPlaceholder(), + }) { + return TestDto( + id: id == const $CopyWithPlaceholder() + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as String?, + questions: questions == const $CopyWithPlaceholder() || questions == null + ? _value.questions + // ignore: cast_nullable_to_non_nullable + : questions as List, + name: name == const $CopyWithPlaceholder() || name == null + ? _value.name + // ignore: cast_nullable_to_non_nullable + : name as String, + time: time == const $CopyWithPlaceholder() + ? _value.time + // ignore: cast_nullable_to_non_nullable + : time as String?, + timeSubtitle: timeSubtitle == const $CopyWithPlaceholder() + ? _value.timeSubtitle + // ignore: cast_nullable_to_non_nullable + : timeSubtitle as String?, + color: color == const $CopyWithPlaceholder() + ? _value.color + // ignore: cast_nullable_to_non_nullable + : color as String?, + cover: cover == const $CopyWithPlaceholder() + ? _value.cover + // ignore: cast_nullable_to_non_nullable + : cover as String?, + statistics: statistics == const $CopyWithPlaceholder() + ? _value.statistics + // ignore: cast_nullable_to_non_nullable + : statistics as TestStatisticsDto?, + version: version == const $CopyWithPlaceholder() + ? _value.version + // ignore: cast_nullable_to_non_nullable + : version as String?, + ); + } +} + +extension $TestDtoCopyWith on TestDto { + /// Returns a callable class that can be used as follows: `instanceOfTestDto.copyWith(...)` or like so:`instanceOfTestDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$TestDtoCWProxy get copyWith => _$TestDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +TestDto _$TestDtoFromJson(Map json) => TestDto( + id: json['id'] as String?, + questions: (json['questions'] as List) + .map((e) => AbstractTestQuestion.fromJson(e as Map)) + .toList(), + name: json['name'] as String, + time: json['time'] as String?, + timeSubtitle: json['timeSubtitle'] as String?, + color: json['color'] as String?, + cover: json['cover'] as String?, + statistics: json['statistics'] == null + ? null + : TestStatisticsDto.fromJson( + json['statistics'] as Map), + version: json['version'] as String?, + ); + +Map _$TestDtoToJson(TestDto instance) => { + 'questions': instance.questions, + 'name': instance.name, + 'color': instance.color, + 'cover': instance.cover, + 'version': instance.version, + 'time': instance.time, + 'timeSubtitle': instance.timeSubtitle, + 'statistics': instance.statistics, + 'id': instance.id, + }; diff --git a/mnemo_cards_common/lib/src/dtos/game_tests/test_bodies/abstract_test_question.dart b/mnemo_cards_common/lib/src/dtos/game_tests/test_bodies/abstract_test_question.dart new file mode 100644 index 0000000..c598687 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/game_tests/test_bodies/abstract_test_question.dart @@ -0,0 +1,40 @@ + +import '../test_question_type.dart'; +import 'input_buttons_test_question_body.dart'; +import 'simple_test_question.dart'; + +abstract class AbstractTestQuestion { + int? id; + final TestQuestionType questionType; + final String word; + final String? body; + + AbstractTestQuestion({ + required this.questionType, + required this.word, + this.body, + this.id, + }); + + Map toJson(); + + factory AbstractTestQuestion.fromJson(Map json) { + final questionType = TestQuestionType.values + .where((element) => element.name == json['questionType']) + .firstOrNull; + switch (questionType) { + case null: + throw Exception('Undefined type'); + case TestQuestionType.simple: + return SimpleTestQuestionBody.fromJson(json); + case TestQuestionType.input_buttons: + return InputButtonsTestQuestionBody.fromJson(json); + case TestQuestionType.matrix: + throw UnimplementedError('Not implemented yet'); + case TestQuestionType.match: + throw UnimplementedError('Not implemented yet'); + case TestQuestionType.undefined: + throw UnimplementedError('Undefined type'); + } + } +} diff --git a/mnemo_cards_common/lib/src/dtos/game_tests/test_bodies/input_buttons_test_question_body.dart b/mnemo_cards_common/lib/src/dtos/game_tests/test_bodies/input_buttons_test_question_body.dart new file mode 100644 index 0000000..a7b0fcd --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/game_tests/test_bodies/input_buttons_test_question_body.dart @@ -0,0 +1,48 @@ + +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:json_annotation/json_annotation.dart'; + +import '../test_button.dart'; +import '../test_question_type.dart'; +import 'abstract_test_question.dart'; + +part 'input_buttons_test_question_body.g.dart'; + +@JsonSerializable(explicitToJson: true, includeIfNull: false) +@CopyWith() +class InputButtonsTestQuestionBody extends AbstractTestQuestion { + final String? image; + final String? text; + final String? audio; + final List buttons; + final String answer; + final String template; + + InputButtonsTestQuestionBody({ + super.id, + required this.answer, + required this.buttons, + required this.template, + required super.word, + this.image, + this.text, + this.audio, + super.questionType = TestQuestionType.input_buttons, + }); + + factory InputButtonsTestQuestionBody.fromJson(Map json) => + _$InputButtonsTestQuestionBodyFromJson(json); + + Map toJson() => _$InputButtonsTestQuestionBodyToJson(this); + +// @override +// TestQuestionBody toTestQuestionBody() => TestQuestionBody( +// id: this.id, +// questionType: this.questionType, +// body: jsonEncode(toJson()), +// ); +} + +extension InputButtonsStringExt on String { + String get asTemplate => this.replaceAll(RegExp('[^ ]'), '_'); +} diff --git a/mnemo_cards_common/lib/src/dtos/game_tests/test_bodies/input_buttons_test_question_body.g.dart b/mnemo_cards_common/lib/src/dtos/game_tests/test_bodies/input_buttons_test_question_body.g.dart new file mode 100644 index 0000000..9172780 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/game_tests/test_bodies/input_buttons_test_question_body.g.dart @@ -0,0 +1,203 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'input_buttons_test_question_body.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$InputButtonsTestQuestionBodyCWProxy { + InputButtonsTestQuestionBody id(int? id); + + InputButtonsTestQuestionBody answer(String answer); + + InputButtonsTestQuestionBody buttons(List buttons); + + InputButtonsTestQuestionBody template(String template); + + InputButtonsTestQuestionBody word(String word); + + InputButtonsTestQuestionBody image(String? image); + + InputButtonsTestQuestionBody text(String? text); + + InputButtonsTestQuestionBody audio(String? audio); + + InputButtonsTestQuestionBody questionType(TestQuestionType questionType); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `InputButtonsTestQuestionBody(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// InputButtonsTestQuestionBody(...).copyWith(id: 12, name: "My name") + /// ```` + InputButtonsTestQuestionBody call({ + int? id, + String? answer, + List? buttons, + String? template, + String? word, + String? image, + String? text, + String? audio, + TestQuestionType? questionType, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfInputButtonsTestQuestionBody.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfInputButtonsTestQuestionBody.copyWith.fieldName(...)` +class _$InputButtonsTestQuestionBodyCWProxyImpl + implements _$InputButtonsTestQuestionBodyCWProxy { + const _$InputButtonsTestQuestionBodyCWProxyImpl(this._value); + + final InputButtonsTestQuestionBody _value; + + @override + InputButtonsTestQuestionBody id(int? id) => this(id: id); + + @override + InputButtonsTestQuestionBody answer(String answer) => this(answer: answer); + + @override + InputButtonsTestQuestionBody buttons(List buttons) => + this(buttons: buttons); + + @override + InputButtonsTestQuestionBody template(String template) => + this(template: template); + + @override + InputButtonsTestQuestionBody word(String word) => this(word: word); + + @override + InputButtonsTestQuestionBody image(String? image) => this(image: image); + + @override + InputButtonsTestQuestionBody text(String? text) => this(text: text); + + @override + InputButtonsTestQuestionBody audio(String? audio) => this(audio: audio); + + @override + InputButtonsTestQuestionBody questionType(TestQuestionType questionType) => + this(questionType: questionType); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `InputButtonsTestQuestionBody(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// InputButtonsTestQuestionBody(...).copyWith(id: 12, name: "My name") + /// ```` + InputButtonsTestQuestionBody call({ + Object? id = const $CopyWithPlaceholder(), + Object? answer = const $CopyWithPlaceholder(), + Object? buttons = const $CopyWithPlaceholder(), + Object? template = const $CopyWithPlaceholder(), + Object? word = const $CopyWithPlaceholder(), + Object? image = const $CopyWithPlaceholder(), + Object? text = const $CopyWithPlaceholder(), + Object? audio = const $CopyWithPlaceholder(), + Object? questionType = const $CopyWithPlaceholder(), + }) { + return InputButtonsTestQuestionBody( + id: id == const $CopyWithPlaceholder() + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as int?, + answer: answer == const $CopyWithPlaceholder() || answer == null + ? _value.answer + // ignore: cast_nullable_to_non_nullable + : answer as String, + buttons: buttons == const $CopyWithPlaceholder() || buttons == null + ? _value.buttons + // ignore: cast_nullable_to_non_nullable + : buttons as List, + template: template == const $CopyWithPlaceholder() || template == null + ? _value.template + // ignore: cast_nullable_to_non_nullable + : template as String, + word: word == const $CopyWithPlaceholder() || word == null + ? _value.word + // ignore: cast_nullable_to_non_nullable + : word as String, + image: image == const $CopyWithPlaceholder() + ? _value.image + // ignore: cast_nullable_to_non_nullable + : image as String?, + text: text == const $CopyWithPlaceholder() + ? _value.text + // ignore: cast_nullable_to_non_nullable + : text as String?, + audio: audio == const $CopyWithPlaceholder() + ? _value.audio + // ignore: cast_nullable_to_non_nullable + : audio as String?, + questionType: + questionType == const $CopyWithPlaceholder() || questionType == null + ? _value.questionType + // ignore: cast_nullable_to_non_nullable + : questionType as TestQuestionType, + ); + } +} + +extension $InputButtonsTestQuestionBodyCopyWith + on InputButtonsTestQuestionBody { + /// Returns a callable class that can be used as follows: `instanceOfInputButtonsTestQuestionBody.copyWith(...)` or like so:`instanceOfInputButtonsTestQuestionBody.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$InputButtonsTestQuestionBodyCWProxy get copyWith => + _$InputButtonsTestQuestionBodyCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +InputButtonsTestQuestionBody _$InputButtonsTestQuestionBodyFromJson( + Map json) => + InputButtonsTestQuestionBody( + id: json['id'] as int?, + answer: json['answer'] as String, + buttons: (json['buttons'] as List) + .map((e) => TestButtonDto.fromJson(e as Map)) + .toList(), + template: json['template'] as String, + word: json['word'] as String, + image: json['image'] as String?, + text: json['text'] as String?, + audio: json['audio'] as String?, + questionType: $enumDecodeNullable( + _$TestQuestionTypeEnumMap, json['questionType']) ?? + TestQuestionType.input_buttons, + ); + +Map _$InputButtonsTestQuestionBodyToJson( + InputButtonsTestQuestionBody instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('id', instance.id); + val['questionType'] = _$TestQuestionTypeEnumMap[instance.questionType]!; + val['word'] = instance.word; + writeNotNull('image', instance.image); + writeNotNull('text', instance.text); + writeNotNull('audio', instance.audio); + val['buttons'] = instance.buttons.map((e) => e.toJson()).toList(); + val['answer'] = instance.answer; + val['template'] = instance.template; + return val; +} + +const _$TestQuestionTypeEnumMap = { + TestQuestionType.simple: 'simple', + TestQuestionType.input_buttons: 'input_buttons', + TestQuestionType.matrix: 'matrix', + TestQuestionType.match: 'match', + TestQuestionType.undefined: 'undefined', +}; diff --git a/mnemo_cards_common/lib/src/dtos/game_tests/test_bodies/simple_test_question.dart b/mnemo_cards_common/lib/src/dtos/game_tests/test_bodies/simple_test_question.dart new file mode 100644 index 0000000..31bcbaa --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/game_tests/test_bodies/simple_test_question.dart @@ -0,0 +1,33 @@ +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:mnemo_cards_common/mnemo_cards_common.dart'; + + +part 'simple_test_question.g.dart'; + +@JsonSerializable(explicitToJson: true, includeIfNull: false) +@CopyWith() +class SimpleTestQuestionBody extends AbstractTestQuestion { + final String? image; + final String? text; + final String? audio; + final List buttons; + final String answer; + + SimpleTestQuestionBody({ + super.id, + required this.answer, + required this.buttons, + required super.word, + this.image, + this.text, + this.audio, + super.questionType = TestQuestionType.simple, + }); + + factory SimpleTestQuestionBody.fromJson(Map json) => + _$SimpleTestQuestionBodyFromJson(json); + + @override + Map toJson() => _$SimpleTestQuestionBodyToJson(this); +} diff --git a/mnemo_cards_common/lib/src/dtos/game_tests/test_bodies/simple_test_question.g.dart b/mnemo_cards_common/lib/src/dtos/game_tests/test_bodies/simple_test_question.g.dart new file mode 100644 index 0000000..85068e0 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/game_tests/test_bodies/simple_test_question.g.dart @@ -0,0 +1,188 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'simple_test_question.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$SimpleTestQuestionBodyCWProxy { + SimpleTestQuestionBody id(int? id); + + SimpleTestQuestionBody answer(String answer); + + SimpleTestQuestionBody buttons(List buttons); + + SimpleTestQuestionBody word(String word); + + SimpleTestQuestionBody image(String? image); + + SimpleTestQuestionBody text(String? text); + + SimpleTestQuestionBody audio(String? audio); + + SimpleTestQuestionBody questionType(TestQuestionType questionType); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SimpleTestQuestionBody(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// SimpleTestQuestionBody(...).copyWith(id: 12, name: "My name") + /// ```` + SimpleTestQuestionBody call({ + int? id, + String? answer, + List? buttons, + String? word, + String? image, + String? text, + String? audio, + TestQuestionType? questionType, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfSimpleTestQuestionBody.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfSimpleTestQuestionBody.copyWith.fieldName(...)` +class _$SimpleTestQuestionBodyCWProxyImpl + implements _$SimpleTestQuestionBodyCWProxy { + const _$SimpleTestQuestionBodyCWProxyImpl(this._value); + + final SimpleTestQuestionBody _value; + + @override + SimpleTestQuestionBody id(int? id) => this(id: id); + + @override + SimpleTestQuestionBody answer(String answer) => this(answer: answer); + + @override + SimpleTestQuestionBody buttons(List buttons) => + this(buttons: buttons); + + @override + SimpleTestQuestionBody word(String word) => this(word: word); + + @override + SimpleTestQuestionBody image(String? image) => this(image: image); + + @override + SimpleTestQuestionBody text(String? text) => this(text: text); + + @override + SimpleTestQuestionBody audio(String? audio) => this(audio: audio); + + @override + SimpleTestQuestionBody questionType(TestQuestionType questionType) => + this(questionType: questionType); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SimpleTestQuestionBody(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// SimpleTestQuestionBody(...).copyWith(id: 12, name: "My name") + /// ```` + SimpleTestQuestionBody call({ + Object? id = const $CopyWithPlaceholder(), + Object? answer = const $CopyWithPlaceholder(), + Object? buttons = const $CopyWithPlaceholder(), + Object? word = const $CopyWithPlaceholder(), + Object? image = const $CopyWithPlaceholder(), + Object? text = const $CopyWithPlaceholder(), + Object? audio = const $CopyWithPlaceholder(), + Object? questionType = const $CopyWithPlaceholder(), + }) { + return SimpleTestQuestionBody( + id: id == const $CopyWithPlaceholder() + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as int?, + answer: answer == const $CopyWithPlaceholder() || answer == null + ? _value.answer + // ignore: cast_nullable_to_non_nullable + : answer as String, + buttons: buttons == const $CopyWithPlaceholder() || buttons == null + ? _value.buttons + // ignore: cast_nullable_to_non_nullable + : buttons as List, + word: word == const $CopyWithPlaceholder() || word == null + ? _value.word + // ignore: cast_nullable_to_non_nullable + : word as String, + image: image == const $CopyWithPlaceholder() + ? _value.image + // ignore: cast_nullable_to_non_nullable + : image as String?, + text: text == const $CopyWithPlaceholder() + ? _value.text + // ignore: cast_nullable_to_non_nullable + : text as String?, + audio: audio == const $CopyWithPlaceholder() + ? _value.audio + // ignore: cast_nullable_to_non_nullable + : audio as String?, + questionType: + questionType == const $CopyWithPlaceholder() || questionType == null + ? _value.questionType + // ignore: cast_nullable_to_non_nullable + : questionType as TestQuestionType, + ); + } +} + +extension $SimpleTestQuestionBodyCopyWith on SimpleTestQuestionBody { + /// Returns a callable class that can be used as follows: `instanceOfSimpleTestQuestionBody.copyWith(...)` or like so:`instanceOfSimpleTestQuestionBody.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$SimpleTestQuestionBodyCWProxy get copyWith => + _$SimpleTestQuestionBodyCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SimpleTestQuestionBody _$SimpleTestQuestionBodyFromJson( + Map json) => + SimpleTestQuestionBody( + id: json['id'] as int?, + answer: json['answer'] as String, + buttons: (json['buttons'] as List) + .map((e) => TestButtonDto.fromJson(e as Map)) + .toList(), + word: json['word'] as String, + image: json['image'] as String?, + text: json['text'] as String?, + audio: json['audio'] as String?, + questionType: $enumDecodeNullable( + _$TestQuestionTypeEnumMap, json['questionType']) ?? + TestQuestionType.simple, + ); + +Map _$SimpleTestQuestionBodyToJson( + SimpleTestQuestionBody instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('id', instance.id); + val['questionType'] = _$TestQuestionTypeEnumMap[instance.questionType]!; + val['word'] = instance.word; + writeNotNull('image', instance.image); + writeNotNull('text', instance.text); + writeNotNull('audio', instance.audio); + val['buttons'] = instance.buttons.map((e) => e.toJson()).toList(); + val['answer'] = instance.answer; + return val; +} + +const _$TestQuestionTypeEnumMap = { + TestQuestionType.simple: 'simple', + TestQuestionType.input_buttons: 'input_buttons', + TestQuestionType.matrix: 'matrix', + TestQuestionType.match: 'match', + TestQuestionType.undefined: 'undefined', +}; diff --git a/mnemo_cards_common/lib/src/dtos/game_tests/test_button.dart b/mnemo_cards_common/lib/src/dtos/game_tests/test_button.dart new file mode 100644 index 0000000..1244468 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/game_tests/test_button.dart @@ -0,0 +1,28 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; + +part 'test_button.g.dart'; + +@CopyWith() +@JsonSerializable(explicitToJson: true, includeIfNull: false) +class TestButtonDto { + final String id; + final String? image; + final String? text; + + TestButtonDto(this.id, this.image, this.text); + + TestButtonDto.text(this.id, this.text) : image = null; + + TestButtonDto.image(this.id, this.image) : text = null; + + bool get isImageButton => image != null; + + bool get isTextButton => !isImageButton; + + factory TestButtonDto.fromJson(Map json) => + _$TestButtonDtoFromJson(json); + + @override + Map toJson() => _$TestButtonDtoToJson(this); +} diff --git a/mnemo_cards_common/lib/src/dtos/game_tests/test_button.g.dart b/mnemo_cards_common/lib/src/dtos/game_tests/test_button.g.dart new file mode 100644 index 0000000..7947fdb --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/game_tests/test_button.g.dart @@ -0,0 +1,105 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'test_button.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$TestButtonDtoCWProxy { + TestButtonDto id(String id); + + TestButtonDto image(String? image); + + TestButtonDto text(String? text); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TestButtonDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// TestButtonDto(...).copyWith(id: 12, name: "My name") + /// ```` + TestButtonDto call({ + String? id, + String? image, + String? text, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfTestButtonDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfTestButtonDto.copyWith.fieldName(...)` +class _$TestButtonDtoCWProxyImpl implements _$TestButtonDtoCWProxy { + const _$TestButtonDtoCWProxyImpl(this._value); + + final TestButtonDto _value; + + @override + TestButtonDto id(String id) => this(id: id); + + @override + TestButtonDto image(String? image) => this(image: image); + + @override + TestButtonDto text(String? text) => this(text: text); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TestButtonDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// TestButtonDto(...).copyWith(id: 12, name: "My name") + /// ```` + TestButtonDto call({ + Object? id = const $CopyWithPlaceholder(), + Object? image = const $CopyWithPlaceholder(), + Object? text = const $CopyWithPlaceholder(), + }) { + return TestButtonDto( + id == const $CopyWithPlaceholder() || id == null + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as String, + image == const $CopyWithPlaceholder() + ? _value.image + // ignore: cast_nullable_to_non_nullable + : image as String?, + text == const $CopyWithPlaceholder() + ? _value.text + // ignore: cast_nullable_to_non_nullable + : text as String?, + ); + } +} + +extension $TestButtonDtoCopyWith on TestButtonDto { + /// Returns a callable class that can be used as follows: `instanceOfTestButtonDto.copyWith(...)` or like so:`instanceOfTestButtonDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$TestButtonDtoCWProxy get copyWith => _$TestButtonDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +TestButtonDto _$TestButtonDtoFromJson(Map json) => + TestButtonDto( + json['id'] as String, + json['image'] as String?, + json['text'] as String?, + ); + +Map _$TestButtonDtoToJson(TestButtonDto instance) { + final val = { + 'id': instance.id, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('image', instance.image); + writeNotNull('text', instance.text); + return val; +} diff --git a/mnemo_cards_common/lib/src/dtos/game_tests/test_question_type.dart b/mnemo_cards_common/lib/src/dtos/game_tests/test_question_type.dart new file mode 100644 index 0000000..26c19bf --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/game_tests/test_question_type.dart @@ -0,0 +1,7 @@ +enum TestQuestionType { + simple, + input_buttons, + matrix, + match, + undefined, +} diff --git a/mnemo_cards_common/lib/src/dtos/game_tests/test_statistics_dto.dart b/mnemo_cards_common/lib/src/dtos/game_tests/test_statistics_dto.dart new file mode 100644 index 0000000..16d8884 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/game_tests/test_statistics_dto.dart @@ -0,0 +1,41 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:mnemo_cards_common/mnemo_cards_common.dart'; + +part 'test_statistics_dto.g.dart'; + +@JsonSerializable() +@CopyWith() +class TestStatisticsDto { + final int testId; + final AllWordsStatisticsDto words; + final String? sessionToken; + final int attempts; + + TestStatisticsDto({ + required this.testId, + required this.words, + this.attempts = 0, + this.sessionToken, + }); + + factory TestStatisticsDto.fromJson(Map json) => + _$TestStatisticsDtoFromJson(json); + + Map toJson() => _$TestStatisticsDtoToJson(this); + + @override + int get hashCode => + testId.hashCode ^ words.hashCode ^ sessionToken.hashCode ^ attempts; + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is TestStatisticsDto && + other.testId == testId && + other.words == words && + other.sessionToken == sessionToken && + other.attempts == attempts; + } +} diff --git a/mnemo_cards_common/lib/src/dtos/game_tests/test_statistics_dto.g.dart b/mnemo_cards_common/lib/src/dtos/game_tests/test_statistics_dto.g.dart new file mode 100644 index 0000000..9859f9d --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/game_tests/test_statistics_dto.g.dart @@ -0,0 +1,112 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'test_statistics_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$TestStatisticsDtoCWProxy { + TestStatisticsDto testId(int testId); + + TestStatisticsDto words(AllWordsStatisticsDto words); + + TestStatisticsDto attempts(int attempts); + + TestStatisticsDto sessionToken(String? sessionToken); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TestStatisticsDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// TestStatisticsDto(...).copyWith(id: 12, name: "My name") + /// ```` + TestStatisticsDto call({ + int? testId, + AllWordsStatisticsDto? words, + int? attempts, + String? sessionToken, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfTestStatisticsDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfTestStatisticsDto.copyWith.fieldName(...)` +class _$TestStatisticsDtoCWProxyImpl implements _$TestStatisticsDtoCWProxy { + const _$TestStatisticsDtoCWProxyImpl(this._value); + + final TestStatisticsDto _value; + + @override + TestStatisticsDto testId(int testId) => this(testId: testId); + + @override + TestStatisticsDto words(AllWordsStatisticsDto words) => this(words: words); + + @override + TestStatisticsDto attempts(int attempts) => this(attempts: attempts); + + @override + TestStatisticsDto sessionToken(String? sessionToken) => + this(sessionToken: sessionToken); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TestStatisticsDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// TestStatisticsDto(...).copyWith(id: 12, name: "My name") + /// ```` + TestStatisticsDto call({ + Object? testId = const $CopyWithPlaceholder(), + Object? words = const $CopyWithPlaceholder(), + Object? attempts = const $CopyWithPlaceholder(), + Object? sessionToken = const $CopyWithPlaceholder(), + }) { + return TestStatisticsDto( + testId: testId == const $CopyWithPlaceholder() || testId == null + ? _value.testId + // ignore: cast_nullable_to_non_nullable + : testId as int, + words: words == const $CopyWithPlaceholder() || words == null + ? _value.words + // ignore: cast_nullable_to_non_nullable + : words as AllWordsStatisticsDto, + attempts: attempts == const $CopyWithPlaceholder() || attempts == null + ? _value.attempts + // ignore: cast_nullable_to_non_nullable + : attempts as int, + sessionToken: sessionToken == const $CopyWithPlaceholder() + ? _value.sessionToken + // ignore: cast_nullable_to_non_nullable + : sessionToken as String?, + ); + } +} + +extension $TestStatisticsDtoCopyWith on TestStatisticsDto { + /// Returns a callable class that can be used as follows: `instanceOfTestStatisticsDto.copyWith(...)` or like so:`instanceOfTestStatisticsDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$TestStatisticsDtoCWProxy get copyWith => + _$TestStatisticsDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +TestStatisticsDto _$TestStatisticsDtoFromJson(Map json) => + TestStatisticsDto( + testId: json['testId'] as int, + words: + AllWordsStatisticsDto.fromJson(json['words'] as Map), + attempts: json['attempts'] as int? ?? 0, + sessionToken: json['sessionToken'] as String?, + ); + +Map _$TestStatisticsDtoToJson(TestStatisticsDto instance) => + { + 'testId': instance.testId, + 'words': instance.words, + 'sessionToken': instance.sessionToken, + 'attempts': instance.attempts, + }; diff --git a/mnemo_cards_common/lib/src/dtos/games/game_dto.dart b/mnemo_cards_common/lib/src/dtos/games/game_dto.dart new file mode 100644 index 0000000..48d8630 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/games/game_dto.dart @@ -0,0 +1,53 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; + +import '../payment/export.dart'; + +part 'game_dto.g.dart'; + +@JsonSerializable(explicitToJson: true, includeIfNull: false) +@CopyWith() +class GameDto implements MnemoCardsProductDto { + final String id; + final String title; + final String subtitle; + final String? color; + final String? version; + final String? imageBase64; + + const GameDto({ + required this.id, + required this.title, + required this.subtitle, + required this.color, + required this.version, + required this.imageBase64, + }); + + factory GameDto.fromJson(Map json) => + _$GameDtoFromJson(json); + + Map toJson() => _$GameDtoToJson(this); + + @override + MnemoCardsProductType get type => MnemoCardsProductType.pack; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is GameDto && + runtimeType == other.runtimeType && + id == other.id && + title == other.title && + subtitle == other.subtitle && + color == other.color && + version == other.version; + + @override + int get hashCode => + id.hashCode ^ + title.hashCode ^ + subtitle.hashCode ^ + color.hashCode ^ + version.hashCode; +} diff --git a/mnemo_cards_common/lib/src/dtos/games/game_dto.g.dart b/mnemo_cards_common/lib/src/dtos/games/game_dto.g.dart new file mode 100644 index 0000000..081df03 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/games/game_dto.g.dart @@ -0,0 +1,143 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'game_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$GameDtoCWProxy { + GameDto id(String id); + + GameDto title(String title); + + GameDto subtitle(String subtitle); + + GameDto color(String? color); + + GameDto version(String? version); + + GameDto imageBase64(String? imageBase64); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `GameDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// GameDto(...).copyWith(id: 12, name: "My name") + /// ```` + GameDto call({ + String? id, + String? title, + String? subtitle, + String? color, + String? version, + String? imageBase64, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfGameDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfGameDto.copyWith.fieldName(...)` +class _$GameDtoCWProxyImpl implements _$GameDtoCWProxy { + const _$GameDtoCWProxyImpl(this._value); + + final GameDto _value; + + @override + GameDto id(String id) => this(id: id); + + @override + GameDto title(String title) => this(title: title); + + @override + GameDto subtitle(String subtitle) => this(subtitle: subtitle); + + @override + GameDto color(String? color) => this(color: color); + + @override + GameDto version(String? version) => this(version: version); + + @override + GameDto imageBase64(String? imageBase64) => this(imageBase64: imageBase64); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `GameDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// GameDto(...).copyWith(id: 12, name: "My name") + /// ```` + GameDto call({ + Object? id = const $CopyWithPlaceholder(), + Object? title = const $CopyWithPlaceholder(), + Object? subtitle = const $CopyWithPlaceholder(), + Object? color = const $CopyWithPlaceholder(), + Object? version = const $CopyWithPlaceholder(), + Object? imageBase64 = const $CopyWithPlaceholder(), + }) { + return GameDto( + id: id == const $CopyWithPlaceholder() || id == null + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as String, + title: title == const $CopyWithPlaceholder() || title == null + ? _value.title + // ignore: cast_nullable_to_non_nullable + : title as String, + subtitle: subtitle == const $CopyWithPlaceholder() || subtitle == null + ? _value.subtitle + // ignore: cast_nullable_to_non_nullable + : subtitle as String, + color: color == const $CopyWithPlaceholder() + ? _value.color + // ignore: cast_nullable_to_non_nullable + : color as String?, + version: version == const $CopyWithPlaceholder() + ? _value.version + // ignore: cast_nullable_to_non_nullable + : version as String?, + imageBase64: imageBase64 == const $CopyWithPlaceholder() + ? _value.imageBase64 + // ignore: cast_nullable_to_non_nullable + : imageBase64 as String?, + ); + } +} + +extension $GameDtoCopyWith on GameDto { + /// Returns a callable class that can be used as follows: `instanceOfGameDto.copyWith(...)` or like so:`instanceOfGameDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$GameDtoCWProxy get copyWith => _$GameDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +GameDto _$GameDtoFromJson(Map json) => GameDto( + id: json['id'] as String, + title: json['title'] as String, + subtitle: json['subtitle'] as String, + color: json['color'] as String?, + version: json['version'] as String?, + imageBase64: json['imageBase64'] as String?, + ); + +Map _$GameDtoToJson(GameDto instance) { + final val = { + 'id': instance.id, + 'title': instance.title, + 'subtitle': instance.subtitle, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('color', instance.color); + writeNotNull('version', instance.version); + writeNotNull('imageBase64', instance.imageBase64); + return val; +} diff --git a/mnemo_cards_common/lib/src/dtos/items/button_item.dart b/mnemo_cards_common/lib/src/dtos/items/button_item.dart new file mode 100644 index 0000000..9d0a169 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/items/button_item.dart @@ -0,0 +1,32 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:mnemo_cards_common/src/dtos/items/item.dart'; + + +part 'button_item.g.dart'; + +@JsonSerializable(includeIfNull: false) +@CopyWith() +class ButtonItem extends Item { + final String? id; + final List? children; + final String? text; + final String? color; + final double height; + + const ButtonItem({ + this.id, + this.children, + this.text, + this.height = 90, + this.color, + super.deeplink, + super.type = ItemType.button, + }); + + factory ButtonItem.fromJson(Map json) => + _$ButtonItemFromJson(json); + + @override + Map toJson() => _$ButtonItemToJson(this); +} diff --git a/mnemo_cards_common/lib/src/dtos/items/button_item.g.dart b/mnemo_cards_common/lib/src/dtos/items/button_item.g.dart new file mode 100644 index 0000000..418668e --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/items/button_item.g.dart @@ -0,0 +1,167 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'button_item.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$ButtonItemCWProxy { + ButtonItem id(String? id); + + ButtonItem children(List? children); + + ButtonItem text(String? text); + + ButtonItem height(double height); + + ButtonItem color(String? color); + + ButtonItem deeplink(String? deeplink); + + ButtonItem type(ItemType type); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `ButtonItem(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// ButtonItem(...).copyWith(id: 12, name: "My name") + /// ```` + ButtonItem call({ + String? id, + List? children, + String? text, + double? height, + String? color, + String? deeplink, + ItemType? type, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfButtonItem.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfButtonItem.copyWith.fieldName(...)` +class _$ButtonItemCWProxyImpl implements _$ButtonItemCWProxy { + const _$ButtonItemCWProxyImpl(this._value); + + final ButtonItem _value; + + @override + ButtonItem id(String? id) => this(id: id); + + @override + ButtonItem children(List? children) => this(children: children); + + @override + ButtonItem text(String? text) => this(text: text); + + @override + ButtonItem height(double height) => this(height: height); + + @override + ButtonItem color(String? color) => this(color: color); + + @override + ButtonItem deeplink(String? deeplink) => this(deeplink: deeplink); + + @override + ButtonItem type(ItemType type) => this(type: type); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `ButtonItem(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// ButtonItem(...).copyWith(id: 12, name: "My name") + /// ```` + ButtonItem call({ + Object? id = const $CopyWithPlaceholder(), + Object? children = const $CopyWithPlaceholder(), + Object? text = const $CopyWithPlaceholder(), + Object? height = const $CopyWithPlaceholder(), + Object? color = const $CopyWithPlaceholder(), + Object? deeplink = const $CopyWithPlaceholder(), + Object? type = const $CopyWithPlaceholder(), + }) { + return ButtonItem( + id: id == const $CopyWithPlaceholder() + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as String?, + children: children == const $CopyWithPlaceholder() + ? _value.children + // ignore: cast_nullable_to_non_nullable + : children as List?, + text: text == const $CopyWithPlaceholder() + ? _value.text + // ignore: cast_nullable_to_non_nullable + : text as String?, + height: height == const $CopyWithPlaceholder() || height == null + ? _value.height + // ignore: cast_nullable_to_non_nullable + : height as double, + color: color == const $CopyWithPlaceholder() + ? _value.color + // ignore: cast_nullable_to_non_nullable + : color as String?, + deeplink: deeplink == const $CopyWithPlaceholder() + ? _value.deeplink + // ignore: cast_nullable_to_non_nullable + : deeplink as String?, + type: type == const $CopyWithPlaceholder() || type == null + ? _value.type + // ignore: cast_nullable_to_non_nullable + : type as ItemType, + ); + } +} + +extension $ButtonItemCopyWith on ButtonItem { + /// Returns a callable class that can be used as follows: `instanceOfButtonItem.copyWith(...)` or like so:`instanceOfButtonItem.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$ButtonItemCWProxy get copyWith => _$ButtonItemCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +ButtonItem _$ButtonItemFromJson(Map json) => ButtonItem( + id: json['id'] as String?, + children: (json['children'] as List?) + ?.map((e) => Item.fromJson(e as Map)) + .toList(), + text: json['text'] as String?, + height: (json['height'] as num?)?.toDouble() ?? 90, + color: json['color'] as String?, + deeplink: json['deeplink'] as String?, + type: $enumDecodeNullable(_$ItemTypeEnumMap, json['type'], + unknownValue: ItemType.unknown) ?? + ItemType.button, + ); + +Map _$ButtonItemToJson(ButtonItem instance) { + final val = { + 'type': _$ItemTypeEnumMap[instance.type]!, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('deeplink', instance.deeplink); + writeNotNull('id', instance.id); + writeNotNull('children', instance.children); + writeNotNull('text', instance.text); + writeNotNull('color', instance.color); + val['height'] = instance.height; + return val; +} + +const _$ItemTypeEnumMap = { + ItemType.text: 'text', + ItemType.spacer: 'spacer', + ItemType.button: 'button', + ItemType.unknown: 'unknown', +}; diff --git a/mnemo_cards_common/lib/src/dtos/items/item.dart b/mnemo_cards_common/lib/src/dtos/items/item.dart new file mode 100644 index 0000000..1907199 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/items/item.dart @@ -0,0 +1,45 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; + +import 'items.dart'; + +part 'item.g.dart'; + +@JsonSerializable(includeIfNull: false) +@CopyWith() +class Item { + final String? id; + @JsonKey(unknownEnumValue: ItemType.unknown) + final ItemType type; + final String? deeplink; + + const Item({ + this.id, + required this.type, + this.deeplink, + }); + + factory Item.fromJson(Map json) { + final item = _$ItemFromJson(json); + switch (item.type) { + case ItemType.text: + return TextItem.fromJson(json); + case ItemType.spacer: + return SpacerItem.fromJson(json); + case ItemType.button: + return ButtonItem.fromJson(json); + case ItemType.unknown: + default: + return item; + } + } + + Map toJson() => _$ItemToJson(this); +} + +enum ItemType { + text, + spacer, + button, + unknown, +} diff --git a/mnemo_cards_common/lib/src/dtos/items/item.g.dart b/mnemo_cards_common/lib/src/dtos/items/item.g.dart new file mode 100644 index 0000000..3a2cce6 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/items/item.g.dart @@ -0,0 +1,111 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'item.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$ItemCWProxy { + Item id(String? id); + + Item type(ItemType type); + + Item deeplink(String? deeplink); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `Item(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// Item(...).copyWith(id: 12, name: "My name") + /// ```` + Item call({ + String? id, + ItemType? type, + String? deeplink, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfItem.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfItem.copyWith.fieldName(...)` +class _$ItemCWProxyImpl implements _$ItemCWProxy { + const _$ItemCWProxyImpl(this._value); + + final Item _value; + + @override + Item id(String? id) => this(id: id); + + @override + Item type(ItemType type) => this(type: type); + + @override + Item deeplink(String? deeplink) => this(deeplink: deeplink); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `Item(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// Item(...).copyWith(id: 12, name: "My name") + /// ```` + Item call({ + Object? id = const $CopyWithPlaceholder(), + Object? type = const $CopyWithPlaceholder(), + Object? deeplink = const $CopyWithPlaceholder(), + }) { + return Item( + id: id == const $CopyWithPlaceholder() + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as String?, + type: type == const $CopyWithPlaceholder() || type == null + ? _value.type + // ignore: cast_nullable_to_non_nullable + : type as ItemType, + deeplink: deeplink == const $CopyWithPlaceholder() + ? _value.deeplink + // ignore: cast_nullable_to_non_nullable + : deeplink as String?, + ); + } +} + +extension $ItemCopyWith on Item { + /// Returns a callable class that can be used as follows: `instanceOfItem.copyWith(...)` or like so:`instanceOfItem.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$ItemCWProxy get copyWith => _$ItemCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Item _$ItemFromJson(Map json) => Item( + id: json['id'] as String?, + type: $enumDecode(_$ItemTypeEnumMap, json['type'], + unknownValue: ItemType.unknown), + deeplink: json['deeplink'] as String?, + ); + +Map _$ItemToJson(Item instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('id', instance.id); + val['type'] = _$ItemTypeEnumMap[instance.type]!; + writeNotNull('deeplink', instance.deeplink); + return val; +} + +const _$ItemTypeEnumMap = { + ItemType.text: 'text', + ItemType.spacer: 'spacer', + ItemType.button: 'button', + ItemType.unknown: 'unknown', +}; diff --git a/mnemo_cards_common/lib/src/dtos/items/items.dart b/mnemo_cards_common/lib/src/dtos/items/items.dart new file mode 100644 index 0000000..3560bcc --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/items/items.dart @@ -0,0 +1,4 @@ +export 'item.dart'; +export 'text_item.dart'; +export 'spacer_item.dart'; +export 'button_item.dart'; diff --git a/mnemo_cards_common/lib/src/dtos/items/spacer_item.dart b/mnemo_cards_common/lib/src/dtos/items/spacer_item.dart new file mode 100644 index 0000000..395d993 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/items/spacer_item.dart @@ -0,0 +1,27 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:mnemo_cards_common/src/dtos/items/item.dart'; + + +part 'spacer_item.g.dart'; + +@JsonSerializable(includeIfNull: false) +@CopyWith() +class SpacerItem extends Item { + final String? id; + final int flex; + final double height; + + const SpacerItem({ + this.id, + this.flex = 1, + this.height = 0, + super.type = ItemType.spacer, + }); + + factory SpacerItem.fromJson(Map json) => + _$SpacerItemFromJson(json); + + @override + Map toJson() => _$SpacerItemToJson(this); +} diff --git a/mnemo_cards_common/lib/src/dtos/items/spacer_item.g.dart b/mnemo_cards_common/lib/src/dtos/items/spacer_item.g.dart new file mode 100644 index 0000000..f022b7c --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/items/spacer_item.g.dart @@ -0,0 +1,126 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'spacer_item.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$SpacerItemCWProxy { + SpacerItem id(String? id); + + SpacerItem flex(int flex); + + SpacerItem height(double height); + + SpacerItem type(ItemType type); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SpacerItem(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// SpacerItem(...).copyWith(id: 12, name: "My name") + /// ```` + SpacerItem call({ + String? id, + int? flex, + double? height, + ItemType? type, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfSpacerItem.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfSpacerItem.copyWith.fieldName(...)` +class _$SpacerItemCWProxyImpl implements _$SpacerItemCWProxy { + const _$SpacerItemCWProxyImpl(this._value); + + final SpacerItem _value; + + @override + SpacerItem id(String? id) => this(id: id); + + @override + SpacerItem flex(int flex) => this(flex: flex); + + @override + SpacerItem height(double height) => this(height: height); + + @override + SpacerItem type(ItemType type) => this(type: type); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SpacerItem(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// SpacerItem(...).copyWith(id: 12, name: "My name") + /// ```` + SpacerItem call({ + Object? id = const $CopyWithPlaceholder(), + Object? flex = const $CopyWithPlaceholder(), + Object? height = const $CopyWithPlaceholder(), + Object? type = const $CopyWithPlaceholder(), + }) { + return SpacerItem( + id: id == const $CopyWithPlaceholder() + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as String?, + flex: flex == const $CopyWithPlaceholder() || flex == null + ? _value.flex + // ignore: cast_nullable_to_non_nullable + : flex as int, + height: height == const $CopyWithPlaceholder() || height == null + ? _value.height + // ignore: cast_nullable_to_non_nullable + : height as double, + type: type == const $CopyWithPlaceholder() || type == null + ? _value.type + // ignore: cast_nullable_to_non_nullable + : type as ItemType, + ); + } +} + +extension $SpacerItemCopyWith on SpacerItem { + /// Returns a callable class that can be used as follows: `instanceOfSpacerItem.copyWith(...)` or like so:`instanceOfSpacerItem.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$SpacerItemCWProxy get copyWith => _$SpacerItemCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SpacerItem _$SpacerItemFromJson(Map json) => SpacerItem( + id: json['id'] as String?, + flex: json['flex'] as int? ?? 1, + height: (json['height'] as num?)?.toDouble() ?? 0, + type: $enumDecodeNullable(_$ItemTypeEnumMap, json['type'], + unknownValue: ItemType.unknown) ?? + ItemType.spacer, + ); + +Map _$SpacerItemToJson(SpacerItem instance) { + final val = { + 'type': _$ItemTypeEnumMap[instance.type]!, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('id', instance.id); + val['flex'] = instance.flex; + val['height'] = instance.height; + return val; +} + +const _$ItemTypeEnumMap = { + ItemType.text: 'text', + ItemType.spacer: 'spacer', + ItemType.button: 'button', + ItemType.unknown: 'unknown', +}; diff --git a/mnemo_cards_common/lib/src/dtos/items/text_item.dart b/mnemo_cards_common/lib/src/dtos/items/text_item.dart new file mode 100644 index 0000000..b605c7e --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/items/text_item.dart @@ -0,0 +1,33 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:mnemo_cards_common/src/dtos/items/item.dart'; + + +part 'text_item.g.dart'; + +@JsonSerializable(includeIfNull: false) +@CopyWith() +class TextItem extends Item { + final String? id; + final String? title; + final String? subtitle; + final String? color; + @JsonKey(defaultValue: false) + final bool hasBorder; + + const TextItem({ + this.id, + this.title, + this.subtitle, + this.color, + this.hasBorder = false, + super.deeplink, + super.type = ItemType.text, + }); + + factory TextItem.fromJson(Map json) => + _$TextItemFromJson(json); + + @override + Map toJson() => _$TextItemToJson(this); +} diff --git a/mnemo_cards_common/lib/src/dtos/items/text_item.g.dart b/mnemo_cards_common/lib/src/dtos/items/text_item.g.dart new file mode 100644 index 0000000..6a6396a --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/items/text_item.g.dart @@ -0,0 +1,165 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'text_item.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$TextItemCWProxy { + TextItem id(String? id); + + TextItem title(String? title); + + TextItem subtitle(String? subtitle); + + TextItem color(String? color); + + TextItem hasBorder(bool hasBorder); + + TextItem deeplink(String? deeplink); + + TextItem type(ItemType type); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TextItem(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// TextItem(...).copyWith(id: 12, name: "My name") + /// ```` + TextItem call({ + String? id, + String? title, + String? subtitle, + String? color, + bool? hasBorder, + String? deeplink, + ItemType? type, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfTextItem.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfTextItem.copyWith.fieldName(...)` +class _$TextItemCWProxyImpl implements _$TextItemCWProxy { + const _$TextItemCWProxyImpl(this._value); + + final TextItem _value; + + @override + TextItem id(String? id) => this(id: id); + + @override + TextItem title(String? title) => this(title: title); + + @override + TextItem subtitle(String? subtitle) => this(subtitle: subtitle); + + @override + TextItem color(String? color) => this(color: color); + + @override + TextItem hasBorder(bool hasBorder) => this(hasBorder: hasBorder); + + @override + TextItem deeplink(String? deeplink) => this(deeplink: deeplink); + + @override + TextItem type(ItemType type) => this(type: type); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TextItem(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// TextItem(...).copyWith(id: 12, name: "My name") + /// ```` + TextItem call({ + Object? id = const $CopyWithPlaceholder(), + Object? title = const $CopyWithPlaceholder(), + Object? subtitle = const $CopyWithPlaceholder(), + Object? color = const $CopyWithPlaceholder(), + Object? hasBorder = const $CopyWithPlaceholder(), + Object? deeplink = const $CopyWithPlaceholder(), + Object? type = const $CopyWithPlaceholder(), + }) { + return TextItem( + id: id == const $CopyWithPlaceholder() + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as String?, + title: title == const $CopyWithPlaceholder() + ? _value.title + // ignore: cast_nullable_to_non_nullable + : title as String?, + subtitle: subtitle == const $CopyWithPlaceholder() + ? _value.subtitle + // ignore: cast_nullable_to_non_nullable + : subtitle as String?, + color: color == const $CopyWithPlaceholder() + ? _value.color + // ignore: cast_nullable_to_non_nullable + : color as String?, + hasBorder: hasBorder == const $CopyWithPlaceholder() || hasBorder == null + ? _value.hasBorder + // ignore: cast_nullable_to_non_nullable + : hasBorder as bool, + deeplink: deeplink == const $CopyWithPlaceholder() + ? _value.deeplink + // ignore: cast_nullable_to_non_nullable + : deeplink as String?, + type: type == const $CopyWithPlaceholder() || type == null + ? _value.type + // ignore: cast_nullable_to_non_nullable + : type as ItemType, + ); + } +} + +extension $TextItemCopyWith on TextItem { + /// Returns a callable class that can be used as follows: `instanceOfTextItem.copyWith(...)` or like so:`instanceOfTextItem.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$TextItemCWProxy get copyWith => _$TextItemCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +TextItem _$TextItemFromJson(Map json) => TextItem( + id: json['id'] as String?, + title: json['title'] as String?, + subtitle: json['subtitle'] as String?, + color: json['color'] as String?, + hasBorder: json['hasBorder'] as bool? ?? false, + deeplink: json['deeplink'] as String?, + type: $enumDecodeNullable(_$ItemTypeEnumMap, json['type'], + unknownValue: ItemType.unknown) ?? + ItemType.text, + ); + +Map _$TextItemToJson(TextItem instance) { + final val = { + 'type': _$ItemTypeEnumMap[instance.type]!, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('deeplink', instance.deeplink); + writeNotNull('id', instance.id); + writeNotNull('title', instance.title); + writeNotNull('subtitle', instance.subtitle); + writeNotNull('color', instance.color); + val['hasBorder'] = instance.hasBorder; + return val; +} + +const _$ItemTypeEnumMap = { + ItemType.text: 'text', + ItemType.spacer: 'spacer', + ItemType.button: 'button', + ItemType.unknown: 'unknown', +}; diff --git a/mnemo_cards_common/lib/src/dtos/packs/card_pack_action.dart b/mnemo_cards_common/lib/src/dtos/packs/card_pack_action.dart new file mode 100644 index 0000000..348f403 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/packs/card_pack_action.dart @@ -0,0 +1,31 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; + +part 'card_pack_action.g.dart'; + +/// Actions for cached packs +/// Update action +@JsonSerializable() +@CopyWith() +class CardPackAction { + final String id; + + @JsonKey(unknownEnumValue: PackAction.unknown) + final PackAction action; + + const CardPackAction({ + required this.id, + required this.action, + }); + + factory CardPackAction.fromJson(Map json) => + _$CardPackActionFromJson(json); + + Map toJson() => _$CardPackActionToJson(this); +} + +enum PackAction { + delete, + update, + unknown, +} diff --git a/mnemo_cards_common/lib/src/dtos/packs/card_pack_action.g.dart b/mnemo_cards_common/lib/src/dtos/packs/card_pack_action.g.dart new file mode 100644 index 0000000..405b609 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/packs/card_pack_action.g.dart @@ -0,0 +1,90 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'card_pack_action.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$CardPackActionCWProxy { + CardPackAction id(String id); + + CardPackAction action(PackAction action); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `CardPackAction(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// CardPackAction(...).copyWith(id: 12, name: "My name") + /// ```` + CardPackAction call({ + String? id, + PackAction? action, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfCardPackAction.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfCardPackAction.copyWith.fieldName(...)` +class _$CardPackActionCWProxyImpl implements _$CardPackActionCWProxy { + const _$CardPackActionCWProxyImpl(this._value); + + final CardPackAction _value; + + @override + CardPackAction id(String id) => this(id: id); + + @override + CardPackAction action(PackAction action) => this(action: action); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `CardPackAction(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// CardPackAction(...).copyWith(id: 12, name: "My name") + /// ```` + CardPackAction call({ + Object? id = const $CopyWithPlaceholder(), + Object? action = const $CopyWithPlaceholder(), + }) { + return CardPackAction( + id: id == const $CopyWithPlaceholder() || id == null + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as String, + action: action == const $CopyWithPlaceholder() || action == null + ? _value.action + // ignore: cast_nullable_to_non_nullable + : action as PackAction, + ); + } +} + +extension $CardPackActionCopyWith on CardPackAction { + /// Returns a callable class that can be used as follows: `instanceOfCardPackAction.copyWith(...)` or like so:`instanceOfCardPackAction.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$CardPackActionCWProxy get copyWith => _$CardPackActionCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +CardPackAction _$CardPackActionFromJson(Map json) => + CardPackAction( + id: json['id'] as String, + action: $enumDecode(_$PackActionEnumMap, json['action'], + unknownValue: PackAction.unknown), + ); + +Map _$CardPackActionToJson(CardPackAction instance) => + { + 'id': instance.id, + 'action': _$PackActionEnumMap[instance.action]!, + }; + +const _$PackActionEnumMap = { + PackAction.delete: 'delete', + PackAction.update: 'update', + PackAction.unknown: 'unknown', +}; diff --git a/mnemo_cards_common/lib/src/dtos/packs/card_pack_buy_dto.dart b/mnemo_cards_common/lib/src/dtos/packs/card_pack_buy_dto.dart new file mode 100644 index 0000000..67d84c6 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/packs/card_pack_buy_dto.dart @@ -0,0 +1,44 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; + +import '../game_card_dto.dart'; +import '../items/item.dart'; +import 'get_card_pack_response.dart'; + +part 'card_pack_buy_dto.g.dart'; + +/// Info for not available packs +@JsonSerializable(explicitToJson: true, includeIfNull: false) +@CopyWith() +class CardPackBuyDto extends GetCardPackResponse { + final String id; + final String title; + final String subtitle; + final String? color; + final String? version; + final List cards; + final List? items; + final String? googlePlayId; + final String? rustoreId; + final String? appStoreId; + final String? price; + + const CardPackBuyDto({ + required this.id, + required this.title, + required this.subtitle, + required this.cards, + this.items, + this.color, + this.version, + this.price, + this.googlePlayId, + this.rustoreId, + this.appStoreId, + }) : super(responseType: GetCardPackResponseType.buy); + + factory CardPackBuyDto.fromJson(Map json) => + _$CardPackBuyDtoFromJson(json); + + Map toJson() => _$CardPackBuyDtoToJson(this); +} diff --git a/mnemo_cards_common/lib/src/dtos/packs/card_pack_buy_dto.g.dart b/mnemo_cards_common/lib/src/dtos/packs/card_pack_buy_dto.g.dart new file mode 100644 index 0000000..b2eb16d --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/packs/card_pack_buy_dto.g.dart @@ -0,0 +1,214 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'card_pack_buy_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$CardPackBuyDtoCWProxy { + CardPackBuyDto id(String id); + + CardPackBuyDto title(String title); + + CardPackBuyDto subtitle(String subtitle); + + CardPackBuyDto cards(List cards); + + CardPackBuyDto items(List? items); + + CardPackBuyDto color(String? color); + + CardPackBuyDto version(String? version); + + CardPackBuyDto price(String? price); + + CardPackBuyDto googlePlayId(String? googlePlayId); + + CardPackBuyDto rustoreId(String? rustoreId); + + CardPackBuyDto appStoreId(String? appStoreId); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `CardPackBuyDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// CardPackBuyDto(...).copyWith(id: 12, name: "My name") + /// ```` + CardPackBuyDto call({ + String? id, + String? title, + String? subtitle, + List? cards, + List? items, + String? color, + String? version, + String? price, + String? googlePlayId, + String? rustoreId, + String? appStoreId, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfCardPackBuyDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfCardPackBuyDto.copyWith.fieldName(...)` +class _$CardPackBuyDtoCWProxyImpl implements _$CardPackBuyDtoCWProxy { + const _$CardPackBuyDtoCWProxyImpl(this._value); + + final CardPackBuyDto _value; + + @override + CardPackBuyDto id(String id) => this(id: id); + + @override + CardPackBuyDto title(String title) => this(title: title); + + @override + CardPackBuyDto subtitle(String subtitle) => this(subtitle: subtitle); + + @override + CardPackBuyDto cards(List cards) => this(cards: cards); + + @override + CardPackBuyDto items(List? items) => this(items: items); + + @override + CardPackBuyDto color(String? color) => this(color: color); + + @override + CardPackBuyDto version(String? version) => this(version: version); + + @override + CardPackBuyDto price(String? price) => this(price: price); + + @override + CardPackBuyDto googlePlayId(String? googlePlayId) => + this(googlePlayId: googlePlayId); + + @override + CardPackBuyDto rustoreId(String? rustoreId) => this(rustoreId: rustoreId); + + @override + CardPackBuyDto appStoreId(String? appStoreId) => this(appStoreId: appStoreId); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `CardPackBuyDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// CardPackBuyDto(...).copyWith(id: 12, name: "My name") + /// ```` + CardPackBuyDto call({ + Object? id = const $CopyWithPlaceholder(), + Object? title = const $CopyWithPlaceholder(), + Object? subtitle = const $CopyWithPlaceholder(), + Object? cards = const $CopyWithPlaceholder(), + Object? items = const $CopyWithPlaceholder(), + Object? color = const $CopyWithPlaceholder(), + Object? version = const $CopyWithPlaceholder(), + Object? price = const $CopyWithPlaceholder(), + Object? googlePlayId = const $CopyWithPlaceholder(), + Object? rustoreId = const $CopyWithPlaceholder(), + Object? appStoreId = const $CopyWithPlaceholder(), + }) { + return CardPackBuyDto( + id: id == const $CopyWithPlaceholder() || id == null + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as String, + title: title == const $CopyWithPlaceholder() || title == null + ? _value.title + // ignore: cast_nullable_to_non_nullable + : title as String, + subtitle: subtitle == const $CopyWithPlaceholder() || subtitle == null + ? _value.subtitle + // ignore: cast_nullable_to_non_nullable + : subtitle as String, + cards: cards == const $CopyWithPlaceholder() || cards == null + ? _value.cards + // ignore: cast_nullable_to_non_nullable + : cards as List, + items: items == const $CopyWithPlaceholder() + ? _value.items + // ignore: cast_nullable_to_non_nullable + : items as List?, + color: color == const $CopyWithPlaceholder() + ? _value.color + // ignore: cast_nullable_to_non_nullable + : color as String?, + version: version == const $CopyWithPlaceholder() + ? _value.version + // ignore: cast_nullable_to_non_nullable + : version as String?, + price: price == const $CopyWithPlaceholder() + ? _value.price + // ignore: cast_nullable_to_non_nullable + : price as String?, + googlePlayId: googlePlayId == const $CopyWithPlaceholder() + ? _value.googlePlayId + // ignore: cast_nullable_to_non_nullable + : googlePlayId as String?, + rustoreId: rustoreId == const $CopyWithPlaceholder() + ? _value.rustoreId + // ignore: cast_nullable_to_non_nullable + : rustoreId as String?, + appStoreId: appStoreId == const $CopyWithPlaceholder() + ? _value.appStoreId + // ignore: cast_nullable_to_non_nullable + : appStoreId as String?, + ); + } +} + +extension $CardPackBuyDtoCopyWith on CardPackBuyDto { + /// Returns a callable class that can be used as follows: `instanceOfCardPackBuyDto.copyWith(...)` or like so:`instanceOfCardPackBuyDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$CardPackBuyDtoCWProxy get copyWith => _$CardPackBuyDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +CardPackBuyDto _$CardPackBuyDtoFromJson(Map json) => + CardPackBuyDto( + id: json['id'] as String, + title: json['title'] as String, + subtitle: json['subtitle'] as String, + cards: (json['cards'] as List) + .map((e) => GameCardDto.fromJson(e as Map)) + .toList(), + items: (json['items'] as List?) + ?.map((e) => Item.fromJson(e as Map)) + .toList(), + color: json['color'] as String?, + version: json['version'] as String?, + price: json['price'] as String?, + googlePlayId: json['googlePlayId'] as String?, + rustoreId: json['rustoreId'] as String?, + appStoreId: json['appStoreId'] as String?, + ); + +Map _$CardPackBuyDtoToJson(CardPackBuyDto instance) { + final val = { + 'id': instance.id, + 'title': instance.title, + 'subtitle': instance.subtitle, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('color', instance.color); + writeNotNull('version', instance.version); + val['cards'] = instance.cards.map((e) => e.toJson()).toList(); + writeNotNull('items', instance.items?.map((e) => e.toJson()).toList()); + writeNotNull('googlePlayId', instance.googlePlayId); + writeNotNull('rustoreId', instance.rustoreId); + writeNotNull('appStoreId', instance.appStoreId); + writeNotNull('price', instance.price); + return val; +} diff --git a/mnemo_cards_common/lib/src/dtos/packs/card_pack_dto.dart b/mnemo_cards_common/lib/src/dtos/packs/card_pack_dto.dart new file mode 100644 index 0000000..fd9fa62 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/packs/card_pack_dto.dart @@ -0,0 +1,59 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:mnemo_cards_common/src/dtos/packs/get_card_pack_response.dart'; + +import '../game_card_dto.dart'; +import '../payment/export.dart'; + +part 'card_pack_dto.g.dart'; + +/// Complete info about the pack (except tests) +/// Used for available packs +@JsonSerializable(explicitToJson: true, includeIfNull: false) +@CopyWith() +class CardPackDto extends GetCardPackResponse implements MnemoCardsProductDto { + final String id; + final String title; + final String subtitle; + final String? color; + final String? version; + final List cards; + + const CardPackDto({ + required this.id, + required this.title, + required this.subtitle, + required this.cards, + required this.color, + required this.version, + }) : super(responseType: GetCardPackResponseType.dto); + + factory CardPackDto.fromJson(Map json) => + _$CardPackDtoFromJson(json); + + Map toJson() => _$CardPackDtoToJson(this); + + @override + MnemoCardsProductType get type => MnemoCardsProductType.pack; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is CardPackDto && + runtimeType == other.runtimeType && + id == other.id && + title == other.title && + subtitle == other.subtitle && + color == other.color && + version == other.version && + cards.length == other.cards.length; + + @override + int get hashCode => + id.hashCode ^ + title.hashCode ^ + subtitle.hashCode ^ + color.hashCode ^ + version.hashCode ^ + cards.length.hashCode; +} diff --git a/mnemo_cards_common/lib/src/dtos/packs/card_pack_dto.g.dart b/mnemo_cards_common/lib/src/dtos/packs/card_pack_dto.g.dart new file mode 100644 index 0000000..6aebab1 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/packs/card_pack_dto.g.dart @@ -0,0 +1,145 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'card_pack_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$CardPackDtoCWProxy { + CardPackDto id(String id); + + CardPackDto title(String title); + + CardPackDto subtitle(String subtitle); + + CardPackDto cards(List cards); + + CardPackDto color(String? color); + + CardPackDto version(String? version); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `CardPackDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// CardPackDto(...).copyWith(id: 12, name: "My name") + /// ```` + CardPackDto call({ + String? id, + String? title, + String? subtitle, + List? cards, + String? color, + String? version, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfCardPackDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfCardPackDto.copyWith.fieldName(...)` +class _$CardPackDtoCWProxyImpl implements _$CardPackDtoCWProxy { + const _$CardPackDtoCWProxyImpl(this._value); + + final CardPackDto _value; + + @override + CardPackDto id(String id) => this(id: id); + + @override + CardPackDto title(String title) => this(title: title); + + @override + CardPackDto subtitle(String subtitle) => this(subtitle: subtitle); + + @override + CardPackDto cards(List cards) => this(cards: cards); + + @override + CardPackDto color(String? color) => this(color: color); + + @override + CardPackDto version(String? version) => this(version: version); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `CardPackDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// CardPackDto(...).copyWith(id: 12, name: "My name") + /// ```` + CardPackDto call({ + Object? id = const $CopyWithPlaceholder(), + Object? title = const $CopyWithPlaceholder(), + Object? subtitle = const $CopyWithPlaceholder(), + Object? cards = const $CopyWithPlaceholder(), + Object? color = const $CopyWithPlaceholder(), + Object? version = const $CopyWithPlaceholder(), + }) { + return CardPackDto( + id: id == const $CopyWithPlaceholder() || id == null + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as String, + title: title == const $CopyWithPlaceholder() || title == null + ? _value.title + // ignore: cast_nullable_to_non_nullable + : title as String, + subtitle: subtitle == const $CopyWithPlaceholder() || subtitle == null + ? _value.subtitle + // ignore: cast_nullable_to_non_nullable + : subtitle as String, + cards: cards == const $CopyWithPlaceholder() || cards == null + ? _value.cards + // ignore: cast_nullable_to_non_nullable + : cards as List, + color: color == const $CopyWithPlaceholder() + ? _value.color + // ignore: cast_nullable_to_non_nullable + : color as String?, + version: version == const $CopyWithPlaceholder() + ? _value.version + // ignore: cast_nullable_to_non_nullable + : version as String?, + ); + } +} + +extension $CardPackDtoCopyWith on CardPackDto { + /// Returns a callable class that can be used as follows: `instanceOfCardPackDto.copyWith(...)` or like so:`instanceOfCardPackDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$CardPackDtoCWProxy get copyWith => _$CardPackDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +CardPackDto _$CardPackDtoFromJson(Map json) => CardPackDto( + id: json['id'] as String, + title: json['title'] as String, + subtitle: json['subtitle'] as String, + cards: (json['cards'] as List) + .map((e) => GameCardDto.fromJson(e as Map)) + .toList(), + color: json['color'] as String?, + version: json['version'] as String?, + ); + +Map _$CardPackDtoToJson(CardPackDto instance) { + final val = { + 'id': instance.id, + 'title': instance.title, + 'subtitle': instance.subtitle, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('color', instance.color); + writeNotNull('version', instance.version); + val['cards'] = instance.cards.map((e) => e.toJson()).toList(); + return val; +} diff --git a/mnemo_cards_common/lib/src/dtos/packs/card_pack_loading_dto.dart b/mnemo_cards_common/lib/src/dtos/packs/card_pack_loading_dto.dart new file mode 100644 index 0000000..ae7bc5f --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/packs/card_pack_loading_dto.dart @@ -0,0 +1,72 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; + +import 'card_pack_preview_dto.dart'; +import 'get_card_pack_response.dart'; + +part 'card_pack_loading_dto.g.dart'; + +/// For the main screen +@JsonSerializable(explicitToJson: true, includeIfNull: false) +@CopyWith() +class CardPackLoadingDto extends GetCardPackResponse { + final String id; + final String? title; + final String? subtitle; + final String? message; + final String? imageId; + final String? color; + final double? loadingProgress; + + const CardPackLoadingDto({ + required this.id, + required this.title, + required this.subtitle, + required this.message, + required this.imageId, + required this.color, + this.loadingProgress, + super.responseType = GetCardPackResponseType.loading, + }); + + factory CardPackLoadingDto.fromId(String id, {String? message}) => + CardPackLoadingDto( + id: id, + title: null, + subtitle: null, + message: message, + imageId: null, + color: null, + ); + + factory CardPackLoadingDto.fromPreviewDto(CardPackPreviewDto dto) => + CardPackLoadingDto( + id: dto.id, + title: dto.title, + subtitle: dto.subtitle, + message: 'Загрузка...', + imageId: 'pack_${dto.id}', + color: dto.color, + ); + + @override + bool operator ==(Object other) => hashCode == other.hashCode; + + @override + int get hashCode => + Object.hashAll([ + id, + title, + subtitle, + message, + imageId, + color, + loadingProgress, + responseType, + ]); + + factory CardPackLoadingDto.fromJson(Map json) => + _$CardPackLoadingDtoFromJson(json); + + Map toJson() => _$CardPackLoadingDtoToJson(this); +} \ No newline at end of file diff --git a/mnemo_cards_common/lib/src/dtos/packs/card_pack_loading_dto.g.dart b/mnemo_cards_common/lib/src/dtos/packs/card_pack_loading_dto.g.dart new file mode 100644 index 0000000..e3a0ff7 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/packs/card_pack_loading_dto.g.dart @@ -0,0 +1,185 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'card_pack_loading_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$CardPackLoadingDtoCWProxy { + CardPackLoadingDto id(String id); + + CardPackLoadingDto title(String? title); + + CardPackLoadingDto subtitle(String? subtitle); + + CardPackLoadingDto message(String? message); + + CardPackLoadingDto imageId(String? imageId); + + CardPackLoadingDto color(String? color); + + CardPackLoadingDto loadingProgress(double? loadingProgress); + + CardPackLoadingDto responseType(GetCardPackResponseType responseType); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `CardPackLoadingDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// CardPackLoadingDto(...).copyWith(id: 12, name: "My name") + /// ```` + CardPackLoadingDto call({ + String? id, + String? title, + String? subtitle, + String? message, + String? imageId, + String? color, + double? loadingProgress, + GetCardPackResponseType? responseType, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfCardPackLoadingDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfCardPackLoadingDto.copyWith.fieldName(...)` +class _$CardPackLoadingDtoCWProxyImpl implements _$CardPackLoadingDtoCWProxy { + const _$CardPackLoadingDtoCWProxyImpl(this._value); + + final CardPackLoadingDto _value; + + @override + CardPackLoadingDto id(String id) => this(id: id); + + @override + CardPackLoadingDto title(String? title) => this(title: title); + + @override + CardPackLoadingDto subtitle(String? subtitle) => this(subtitle: subtitle); + + @override + CardPackLoadingDto message(String? message) => this(message: message); + + @override + CardPackLoadingDto imageId(String? imageId) => this(imageId: imageId); + + @override + CardPackLoadingDto color(String? color) => this(color: color); + + @override + CardPackLoadingDto loadingProgress(double? loadingProgress) => + this(loadingProgress: loadingProgress); + + @override + CardPackLoadingDto responseType(GetCardPackResponseType responseType) => + this(responseType: responseType); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `CardPackLoadingDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// CardPackLoadingDto(...).copyWith(id: 12, name: "My name") + /// ```` + CardPackLoadingDto call({ + Object? id = const $CopyWithPlaceholder(), + Object? title = const $CopyWithPlaceholder(), + Object? subtitle = const $CopyWithPlaceholder(), + Object? message = const $CopyWithPlaceholder(), + Object? imageId = const $CopyWithPlaceholder(), + Object? color = const $CopyWithPlaceholder(), + Object? loadingProgress = const $CopyWithPlaceholder(), + Object? responseType = const $CopyWithPlaceholder(), + }) { + return CardPackLoadingDto( + id: id == const $CopyWithPlaceholder() || id == null + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as String, + title: title == const $CopyWithPlaceholder() + ? _value.title + // ignore: cast_nullable_to_non_nullable + : title as String?, + subtitle: subtitle == const $CopyWithPlaceholder() + ? _value.subtitle + // ignore: cast_nullable_to_non_nullable + : subtitle as String?, + message: message == const $CopyWithPlaceholder() + ? _value.message + // ignore: cast_nullable_to_non_nullable + : message as String?, + imageId: imageId == const $CopyWithPlaceholder() + ? _value.imageId + // ignore: cast_nullable_to_non_nullable + : imageId as String?, + color: color == const $CopyWithPlaceholder() + ? _value.color + // ignore: cast_nullable_to_non_nullable + : color as String?, + loadingProgress: loadingProgress == const $CopyWithPlaceholder() + ? _value.loadingProgress + // ignore: cast_nullable_to_non_nullable + : loadingProgress as double?, + responseType: + responseType == const $CopyWithPlaceholder() || responseType == null + ? _value.responseType + // ignore: cast_nullable_to_non_nullable + : responseType as GetCardPackResponseType, + ); + } +} + +extension $CardPackLoadingDtoCopyWith on CardPackLoadingDto { + /// Returns a callable class that can be used as follows: `instanceOfCardPackLoadingDto.copyWith(...)` or like so:`instanceOfCardPackLoadingDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$CardPackLoadingDtoCWProxy get copyWith => + _$CardPackLoadingDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +CardPackLoadingDto _$CardPackLoadingDtoFromJson(Map json) => + CardPackLoadingDto( + id: json['id'] as String, + title: json['title'] as String?, + subtitle: json['subtitle'] as String?, + message: json['message'] as String?, + imageId: json['imageId'] as String?, + color: json['color'] as String?, + loadingProgress: (json['loadingProgress'] as num?)?.toDouble(), + responseType: $enumDecodeNullable( + _$GetCardPackResponseTypeEnumMap, json['responseType'], + unknownValue: GetCardPackResponseType.unknown) ?? + GetCardPackResponseType.loading, + ); + +Map _$CardPackLoadingDtoToJson(CardPackLoadingDto instance) { + final val = { + 'responseType': _$GetCardPackResponseTypeEnumMap[instance.responseType]!, + 'id': instance.id, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('title', instance.title); + writeNotNull('subtitle', instance.subtitle); + writeNotNull('message', instance.message); + writeNotNull('imageId', instance.imageId); + writeNotNull('color', instance.color); + writeNotNull('loadingProgress', instance.loadingProgress); + return val; +} + +const _$GetCardPackResponseTypeEnumMap = { + GetCardPackResponseType.buy: 'buy', + GetCardPackResponseType.dto: 'dto', + GetCardPackResponseType.edit: 'edit', + GetCardPackResponseType.loading: 'loading', + GetCardPackResponseType.unknown: 'unknown', +}; diff --git a/mnemo_cards_common/lib/src/dtos/packs/card_pack_preview_dto.dart b/mnemo_cards_common/lib/src/dtos/packs/card_pack_preview_dto.dart new file mode 100644 index 0000000..504a1de --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/packs/card_pack_preview_dto.dart @@ -0,0 +1,68 @@ +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:mnemo_cards_common/mnemo_cards_common.dart'; + +import 'pack_tip.dart'; + + +part 'card_pack_preview_dto.g.dart'; + +/// For the main screen +@JsonSerializable(explicitToJson: true, includeIfNull: false) +@CopyWith() +class CardPackPreviewDto + implements MnemoCardsProductDto { + final String id; + final String title; + final String? subtitle; + final int? cards; + final int? tests; + final String? price; + final String? imageBase64; + final String? color; + @JsonKey(defaultValue: false) + final bool isAvailable; + final PackTip? tip; + final String? version; + + const CardPackPreviewDto({ + required this.id, + required this.title, + required this.subtitle, + required this.cards, + required this.tests, + required this.price, + required this.imageBase64, + required this.color, + required this.isAvailable, + required this.tip, + required this.version, + }); + + @override + bool operator ==(Object other) => hashCode == other.hashCode; + + @override + int get hashCode => + Object.hashAll([ + id, + title, + subtitle, + cards, + tests, + price, + imageBase64, + color, + isAvailable, + version, + tip, + ]); + + factory CardPackPreviewDto.fromJson(Map json) => + _$CardPackPreviewDtoFromJson(json); + + Map toJson() => _$CardPackPreviewDtoToJson(this); + + @override + MnemoCardsProductType get type => MnemoCardsProductType.pack; +} diff --git a/mnemo_cards_common/lib/src/dtos/packs/card_pack_preview_dto.g.dart b/mnemo_cards_common/lib/src/dtos/packs/card_pack_preview_dto.g.dart new file mode 100644 index 0000000..699cf17 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/packs/card_pack_preview_dto.g.dart @@ -0,0 +1,215 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'card_pack_preview_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$CardPackPreviewDtoCWProxy { + CardPackPreviewDto id(String id); + + CardPackPreviewDto title(String title); + + CardPackPreviewDto subtitle(String? subtitle); + + CardPackPreviewDto cards(int? cards); + + CardPackPreviewDto tests(int? tests); + + CardPackPreviewDto price(String? price); + + CardPackPreviewDto imageBase64(String? imageBase64); + + CardPackPreviewDto color(String? color); + + CardPackPreviewDto isAvailable(bool isAvailable); + + CardPackPreviewDto tip(PackTip? tip); + + CardPackPreviewDto version(String? version); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `CardPackPreviewDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// CardPackPreviewDto(...).copyWith(id: 12, name: "My name") + /// ```` + CardPackPreviewDto call({ + String? id, + String? title, + String? subtitle, + int? cards, + int? tests, + String? price, + String? imageBase64, + String? color, + bool? isAvailable, + PackTip? tip, + String? version, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfCardPackPreviewDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfCardPackPreviewDto.copyWith.fieldName(...)` +class _$CardPackPreviewDtoCWProxyImpl implements _$CardPackPreviewDtoCWProxy { + const _$CardPackPreviewDtoCWProxyImpl(this._value); + + final CardPackPreviewDto _value; + + @override + CardPackPreviewDto id(String id) => this(id: id); + + @override + CardPackPreviewDto title(String title) => this(title: title); + + @override + CardPackPreviewDto subtitle(String? subtitle) => this(subtitle: subtitle); + + @override + CardPackPreviewDto cards(int? cards) => this(cards: cards); + + @override + CardPackPreviewDto tests(int? tests) => this(tests: tests); + + @override + CardPackPreviewDto price(String? price) => this(price: price); + + @override + CardPackPreviewDto imageBase64(String? imageBase64) => + this(imageBase64: imageBase64); + + @override + CardPackPreviewDto color(String? color) => this(color: color); + + @override + CardPackPreviewDto isAvailable(bool isAvailable) => + this(isAvailable: isAvailable); + + @override + CardPackPreviewDto tip(PackTip? tip) => this(tip: tip); + + @override + CardPackPreviewDto version(String? version) => this(version: version); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `CardPackPreviewDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// CardPackPreviewDto(...).copyWith(id: 12, name: "My name") + /// ```` + CardPackPreviewDto call({ + Object? id = const $CopyWithPlaceholder(), + Object? title = const $CopyWithPlaceholder(), + Object? subtitle = const $CopyWithPlaceholder(), + Object? cards = const $CopyWithPlaceholder(), + Object? tests = const $CopyWithPlaceholder(), + Object? price = const $CopyWithPlaceholder(), + Object? imageBase64 = const $CopyWithPlaceholder(), + Object? color = const $CopyWithPlaceholder(), + Object? isAvailable = const $CopyWithPlaceholder(), + Object? tip = const $CopyWithPlaceholder(), + Object? version = const $CopyWithPlaceholder(), + }) { + return CardPackPreviewDto( + id: id == const $CopyWithPlaceholder() || id == null + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as String, + title: title == const $CopyWithPlaceholder() || title == null + ? _value.title + // ignore: cast_nullable_to_non_nullable + : title as String, + subtitle: subtitle == const $CopyWithPlaceholder() + ? _value.subtitle + // ignore: cast_nullable_to_non_nullable + : subtitle as String?, + cards: cards == const $CopyWithPlaceholder() + ? _value.cards + // ignore: cast_nullable_to_non_nullable + : cards as int?, + tests: tests == const $CopyWithPlaceholder() + ? _value.tests + // ignore: cast_nullable_to_non_nullable + : tests as int?, + price: price == const $CopyWithPlaceholder() + ? _value.price + // ignore: cast_nullable_to_non_nullable + : price as String?, + imageBase64: imageBase64 == const $CopyWithPlaceholder() + ? _value.imageBase64 + // ignore: cast_nullable_to_non_nullable + : imageBase64 as String?, + color: color == const $CopyWithPlaceholder() + ? _value.color + // ignore: cast_nullable_to_non_nullable + : color as String?, + isAvailable: + isAvailable == const $CopyWithPlaceholder() || isAvailable == null + ? _value.isAvailable + // ignore: cast_nullable_to_non_nullable + : isAvailable as bool, + tip: tip == const $CopyWithPlaceholder() + ? _value.tip + // ignore: cast_nullable_to_non_nullable + : tip as PackTip?, + version: version == const $CopyWithPlaceholder() + ? _value.version + // ignore: cast_nullable_to_non_nullable + : version as String?, + ); + } +} + +extension $CardPackPreviewDtoCopyWith on CardPackPreviewDto { + /// Returns a callable class that can be used as follows: `instanceOfCardPackPreviewDto.copyWith(...)` or like so:`instanceOfCardPackPreviewDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$CardPackPreviewDtoCWProxy get copyWith => + _$CardPackPreviewDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +CardPackPreviewDto _$CardPackPreviewDtoFromJson(Map json) => + CardPackPreviewDto( + id: json['id'] as String, + title: json['title'] as String, + subtitle: json['subtitle'] as String?, + cards: json['cards'] as int?, + tests: json['tests'] as int?, + price: json['price'] as String?, + imageBase64: json['imageBase64'] as String?, + color: json['color'] as String?, + isAvailable: json['isAvailable'] as bool? ?? false, + tip: json['tip'] == null + ? null + : PackTip.fromJson(json['tip'] as Map), + version: json['version'] as String?, + ); + +Map _$CardPackPreviewDtoToJson(CardPackPreviewDto instance) { + final val = { + 'id': instance.id, + 'title': instance.title, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('subtitle', instance.subtitle); + writeNotNull('cards', instance.cards); + writeNotNull('tests', instance.tests); + writeNotNull('price', instance.price); + writeNotNull('imageBase64', instance.imageBase64); + writeNotNull('color', instance.color); + val['isAvailable'] = instance.isAvailable; + writeNotNull('tip', instance.tip?.toJson()); + writeNotNull('version', instance.version); + return val; +} diff --git a/mnemo_cards_common/lib/src/dtos/packs/edit_card_pack_dto.dart b/mnemo_cards_common/lib/src/dtos/packs/edit_card_pack_dto.dart new file mode 100644 index 0000000..c1d7143 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/packs/edit_card_pack_dto.dart @@ -0,0 +1,61 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:mnemo_cards_common/src/dtos/packs/get_card_pack_response.dart'; + +part 'edit_card_pack_dto.g.dart'; + +/// Complete info about the pack (except tests) +/// Used for available packs +@JsonSerializable(explicitToJson: true, includeIfNull: false) +@CopyWith() +class EditCardPackDto extends GetCardPackResponse { + final String? id; + final String? title; + final String? subtitle; + final String? color; + final String? cover; + final int? size; + final String? googlePlayId; + final String? rustoreId; + final String? appStoreId; + final String? price; + final String? description; + final bool? enabled; + final String? version; + final List? addCardIds; + final List? addTestIds; + final List? removeCardIds; + final List? removeTestIds; + final List? cardsOrder; + final int? order; + + final List? previewCards; + + const EditCardPackDto({ + required this.id, + required this.title, + required this.subtitle, + required this.color, + required this.cover, + required this.size, + required this.googlePlayId, + required this.rustoreId, + required this.appStoreId, + required this.price, + required this.description, + required this.enabled, + required this.addCardIds, + required this.addTestIds, + required this.removeCardIds, + required this.removeTestIds, + required this.previewCards, + required this.version, + required this.order, + required this.cardsOrder, + }) : super(responseType: GetCardPackResponseType.edit); + + factory EditCardPackDto.fromJson(Map json) => + _$EditCardPackDtoFromJson(json); + + Map toJson() => _$EditCardPackDtoToJson(this); +} diff --git a/mnemo_cards_common/lib/src/dtos/packs/edit_card_pack_dto.g.dart b/mnemo_cards_common/lib/src/dtos/packs/edit_card_pack_dto.g.dart new file mode 100644 index 0000000..7795c9f --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/packs/edit_card_pack_dto.g.dart @@ -0,0 +1,345 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'edit_card_pack_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$EditCardPackDtoCWProxy { + EditCardPackDto id(String? id); + + EditCardPackDto title(String? title); + + EditCardPackDto subtitle(String? subtitle); + + EditCardPackDto color(String? color); + + EditCardPackDto cover(String? cover); + + EditCardPackDto size(int? size); + + EditCardPackDto googlePlayId(String? googlePlayId); + + EditCardPackDto rustoreId(String? rustoreId); + + EditCardPackDto appStoreId(String? appStoreId); + + EditCardPackDto price(String? price); + + EditCardPackDto description(String? description); + + EditCardPackDto enabled(bool? enabled); + + EditCardPackDto addCardIds(List? addCardIds); + + EditCardPackDto addTestIds(List? addTestIds); + + EditCardPackDto removeCardIds(List? removeCardIds); + + EditCardPackDto removeTestIds(List? removeTestIds); + + EditCardPackDto previewCards(List? previewCards); + + EditCardPackDto version(String? version); + + EditCardPackDto order(int? order); + + EditCardPackDto cardsOrder(List? cardsOrder); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `EditCardPackDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// EditCardPackDto(...).copyWith(id: 12, name: "My name") + /// ```` + EditCardPackDto call({ + String? id, + String? title, + String? subtitle, + String? color, + String? cover, + int? size, + String? googlePlayId, + String? rustoreId, + String? appStoreId, + String? price, + String? description, + bool? enabled, + List? addCardIds, + List? addTestIds, + List? removeCardIds, + List? removeTestIds, + List? previewCards, + String? version, + int? order, + List? cardsOrder, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfEditCardPackDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfEditCardPackDto.copyWith.fieldName(...)` +class _$EditCardPackDtoCWProxyImpl implements _$EditCardPackDtoCWProxy { + const _$EditCardPackDtoCWProxyImpl(this._value); + + final EditCardPackDto _value; + + @override + EditCardPackDto id(String? id) => this(id: id); + + @override + EditCardPackDto title(String? title) => this(title: title); + + @override + EditCardPackDto subtitle(String? subtitle) => this(subtitle: subtitle); + + @override + EditCardPackDto color(String? color) => this(color: color); + + @override + EditCardPackDto cover(String? cover) => this(cover: cover); + + @override + EditCardPackDto size(int? size) => this(size: size); + + @override + EditCardPackDto googlePlayId(String? googlePlayId) => + this(googlePlayId: googlePlayId); + + @override + EditCardPackDto rustoreId(String? rustoreId) => this(rustoreId: rustoreId); + + @override + EditCardPackDto appStoreId(String? appStoreId) => + this(appStoreId: appStoreId); + + @override + EditCardPackDto price(String? price) => this(price: price); + + @override + EditCardPackDto description(String? description) => + this(description: description); + + @override + EditCardPackDto enabled(bool? enabled) => this(enabled: enabled); + + @override + EditCardPackDto addCardIds(List? addCardIds) => + this(addCardIds: addCardIds); + + @override + EditCardPackDto addTestIds(List? addTestIds) => + this(addTestIds: addTestIds); + + @override + EditCardPackDto removeCardIds(List? removeCardIds) => + this(removeCardIds: removeCardIds); + + @override + EditCardPackDto removeTestIds(List? removeTestIds) => + this(removeTestIds: removeTestIds); + + @override + EditCardPackDto previewCards(List? previewCards) => + this(previewCards: previewCards); + + @override + EditCardPackDto version(String? version) => this(version: version); + + @override + EditCardPackDto order(int? order) => this(order: order); + + @override + EditCardPackDto cardsOrder(List? cardsOrder) => + this(cardsOrder: cardsOrder); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `EditCardPackDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// EditCardPackDto(...).copyWith(id: 12, name: "My name") + /// ```` + EditCardPackDto call({ + Object? id = const $CopyWithPlaceholder(), + Object? title = const $CopyWithPlaceholder(), + Object? subtitle = const $CopyWithPlaceholder(), + Object? color = const $CopyWithPlaceholder(), + Object? cover = const $CopyWithPlaceholder(), + Object? size = const $CopyWithPlaceholder(), + Object? googlePlayId = const $CopyWithPlaceholder(), + Object? rustoreId = const $CopyWithPlaceholder(), + Object? appStoreId = const $CopyWithPlaceholder(), + Object? price = const $CopyWithPlaceholder(), + Object? description = const $CopyWithPlaceholder(), + Object? enabled = const $CopyWithPlaceholder(), + Object? addCardIds = const $CopyWithPlaceholder(), + Object? addTestIds = const $CopyWithPlaceholder(), + Object? removeCardIds = const $CopyWithPlaceholder(), + Object? removeTestIds = const $CopyWithPlaceholder(), + Object? previewCards = const $CopyWithPlaceholder(), + Object? version = const $CopyWithPlaceholder(), + Object? order = const $CopyWithPlaceholder(), + Object? cardsOrder = const $CopyWithPlaceholder(), + }) { + return EditCardPackDto( + id: id == const $CopyWithPlaceholder() + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as String?, + title: title == const $CopyWithPlaceholder() + ? _value.title + // ignore: cast_nullable_to_non_nullable + : title as String?, + subtitle: subtitle == const $CopyWithPlaceholder() + ? _value.subtitle + // ignore: cast_nullable_to_non_nullable + : subtitle as String?, + color: color == const $CopyWithPlaceholder() + ? _value.color + // ignore: cast_nullable_to_non_nullable + : color as String?, + cover: cover == const $CopyWithPlaceholder() + ? _value.cover + // ignore: cast_nullable_to_non_nullable + : cover as String?, + size: size == const $CopyWithPlaceholder() + ? _value.size + // ignore: cast_nullable_to_non_nullable + : size as int?, + googlePlayId: googlePlayId == const $CopyWithPlaceholder() + ? _value.googlePlayId + // ignore: cast_nullable_to_non_nullable + : googlePlayId as String?, + rustoreId: rustoreId == const $CopyWithPlaceholder() + ? _value.rustoreId + // ignore: cast_nullable_to_non_nullable + : rustoreId as String?, + appStoreId: appStoreId == const $CopyWithPlaceholder() + ? _value.appStoreId + // ignore: cast_nullable_to_non_nullable + : appStoreId as String?, + price: price == const $CopyWithPlaceholder() + ? _value.price + // ignore: cast_nullable_to_non_nullable + : price as String?, + description: description == const $CopyWithPlaceholder() + ? _value.description + // ignore: cast_nullable_to_non_nullable + : description as String?, + enabled: enabled == const $CopyWithPlaceholder() + ? _value.enabled + // ignore: cast_nullable_to_non_nullable + : enabled as bool?, + addCardIds: addCardIds == const $CopyWithPlaceholder() + ? _value.addCardIds + // ignore: cast_nullable_to_non_nullable + : addCardIds as List?, + addTestIds: addTestIds == const $CopyWithPlaceholder() + ? _value.addTestIds + // ignore: cast_nullable_to_non_nullable + : addTestIds as List?, + removeCardIds: removeCardIds == const $CopyWithPlaceholder() + ? _value.removeCardIds + // ignore: cast_nullable_to_non_nullable + : removeCardIds as List?, + removeTestIds: removeTestIds == const $CopyWithPlaceholder() + ? _value.removeTestIds + // ignore: cast_nullable_to_non_nullable + : removeTestIds as List?, + previewCards: previewCards == const $CopyWithPlaceholder() + ? _value.previewCards + // ignore: cast_nullable_to_non_nullable + : previewCards as List?, + version: version == const $CopyWithPlaceholder() + ? _value.version + // ignore: cast_nullable_to_non_nullable + : version as String?, + order: order == const $CopyWithPlaceholder() + ? _value.order + // ignore: cast_nullable_to_non_nullable + : order as int?, + cardsOrder: cardsOrder == const $CopyWithPlaceholder() + ? _value.cardsOrder + // ignore: cast_nullable_to_non_nullable + : cardsOrder as List?, + ); + } +} + +extension $EditCardPackDtoCopyWith on EditCardPackDto { + /// Returns a callable class that can be used as follows: `instanceOfEditCardPackDto.copyWith(...)` or like so:`instanceOfEditCardPackDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$EditCardPackDtoCWProxy get copyWith => _$EditCardPackDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +EditCardPackDto _$EditCardPackDtoFromJson(Map json) => + EditCardPackDto( + id: json['id'] as String?, + title: json['title'] as String?, + subtitle: json['subtitle'] as String?, + color: json['color'] as String?, + cover: json['cover'] as String?, + size: json['size'] as int?, + googlePlayId: json['googlePlayId'] as String?, + rustoreId: json['rustoreId'] as String?, + appStoreId: json['appStoreId'] as String?, + price: json['price'] as String?, + description: json['description'] as String?, + enabled: json['enabled'] as bool?, + addCardIds: (json['addCardIds'] as List?) + ?.map((e) => e as String) + .toList(), + addTestIds: (json['addTestIds'] as List?) + ?.map((e) => e as String) + .toList(), + removeCardIds: (json['removeCardIds'] as List?) + ?.map((e) => e as String) + .toList(), + removeTestIds: (json['removeTestIds'] as List?) + ?.map((e) => e as String) + .toList(), + previewCards: (json['previewCards'] as List?) + ?.map((e) => e as String) + .toList(), + version: json['version'] as String?, + order: json['order'] as int?, + cardsOrder: + (json['cardsOrder'] as List?)?.map((e) => e as int).toList(), + ); + +Map _$EditCardPackDtoToJson(EditCardPackDto instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('id', instance.id); + writeNotNull('title', instance.title); + writeNotNull('subtitle', instance.subtitle); + writeNotNull('color', instance.color); + writeNotNull('cover', instance.cover); + writeNotNull('size', instance.size); + writeNotNull('googlePlayId', instance.googlePlayId); + writeNotNull('rustoreId', instance.rustoreId); + writeNotNull('appStoreId', instance.appStoreId); + writeNotNull('price', instance.price); + writeNotNull('description', instance.description); + writeNotNull('enabled', instance.enabled); + writeNotNull('version', instance.version); + writeNotNull('addCardIds', instance.addCardIds); + writeNotNull('addTestIds', instance.addTestIds); + writeNotNull('removeCardIds', instance.removeCardIds); + writeNotNull('removeTestIds', instance.removeTestIds); + writeNotNull('cardsOrder', instance.cardsOrder); + writeNotNull('order', instance.order); + writeNotNull('previewCards', instance.previewCards); + return val; +} diff --git a/mnemo_cards_common/lib/src/dtos/packs/get_card_pack_response.dart b/mnemo_cards_common/lib/src/dtos/packs/get_card_pack_response.dart new file mode 100644 index 0000000..efab0d8 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/packs/get_card_pack_response.dart @@ -0,0 +1,50 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:mnemo_cards_common/src/dtos/packs/card_pack_buy_dto.dart'; +import 'package:mnemo_cards_common/src/dtos/packs/edit_card_pack_dto.dart'; + +import 'card_pack_dto.dart'; +import 'card_pack_loading_dto.dart'; + +part 'get_card_pack_response.g.dart'; + +/// Actions for cached packs +/// Update action +@JsonSerializable() +@CopyWith() +class GetCardPackResponse { + @JsonKey(unknownEnumValue: GetCardPackResponseType.unknown) + final GetCardPackResponseType responseType; + + String? get id => null; + + const GetCardPackResponse({ + required this.responseType, + }); + + factory GetCardPackResponse.fromJson(Map json) { + final response = _$GetCardPackResponseFromJson(json); + switch (response.responseType) { + case GetCardPackResponseType.buy: + return CardPackBuyDto.fromJson(json); + case GetCardPackResponseType.dto: + return CardPackDto.fromJson(json); + case GetCardPackResponseType.edit: + return EditCardPackDto.fromJson(json); + case GetCardPackResponseType.loading: + return CardPackLoadingDto.fromJson(json); + case GetCardPackResponseType.unknown: + return response; + } + } + + Map toJson() => _$GetCardPackResponseToJson(this); +} + +enum GetCardPackResponseType { + buy, + dto, + edit, + loading, + unknown, +} diff --git a/mnemo_cards_common/lib/src/dtos/packs/get_card_pack_response.g.dart b/mnemo_cards_common/lib/src/dtos/packs/get_card_pack_response.g.dart new file mode 100644 index 0000000..c6e9ac4 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/packs/get_card_pack_response.g.dart @@ -0,0 +1,84 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'get_card_pack_response.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$GetCardPackResponseCWProxy { + GetCardPackResponse responseType(GetCardPackResponseType responseType); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `GetCardPackResponse(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// GetCardPackResponse(...).copyWith(id: 12, name: "My name") + /// ```` + GetCardPackResponse call({ + GetCardPackResponseType? responseType, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfGetCardPackResponse.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfGetCardPackResponse.copyWith.fieldName(...)` +class _$GetCardPackResponseCWProxyImpl implements _$GetCardPackResponseCWProxy { + const _$GetCardPackResponseCWProxyImpl(this._value); + + final GetCardPackResponse _value; + + @override + GetCardPackResponse responseType(GetCardPackResponseType responseType) => + this(responseType: responseType); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `GetCardPackResponse(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// GetCardPackResponse(...).copyWith(id: 12, name: "My name") + /// ```` + GetCardPackResponse call({ + Object? responseType = const $CopyWithPlaceholder(), + }) { + return GetCardPackResponse( + responseType: + responseType == const $CopyWithPlaceholder() || responseType == null + ? _value.responseType + // ignore: cast_nullable_to_non_nullable + : responseType as GetCardPackResponseType, + ); + } +} + +extension $GetCardPackResponseCopyWith on GetCardPackResponse { + /// Returns a callable class that can be used as follows: `instanceOfGetCardPackResponse.copyWith(...)` or like so:`instanceOfGetCardPackResponse.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$GetCardPackResponseCWProxy get copyWith => + _$GetCardPackResponseCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +GetCardPackResponse _$GetCardPackResponseFromJson(Map json) => + GetCardPackResponse( + responseType: $enumDecode( + _$GetCardPackResponseTypeEnumMap, json['responseType'], + unknownValue: GetCardPackResponseType.unknown), + ); + +Map _$GetCardPackResponseToJson( + GetCardPackResponse instance) => + { + 'responseType': _$GetCardPackResponseTypeEnumMap[instance.responseType]!, + }; + +const _$GetCardPackResponseTypeEnumMap = { + GetCardPackResponseType.buy: 'buy', + GetCardPackResponseType.dto: 'dto', + GetCardPackResponseType.edit: 'edit', + GetCardPackResponseType.loading: 'loading', + GetCardPackResponseType.unknown: 'unknown', +}; diff --git a/mnemo_cards_common/lib/src/dtos/packs/pack_tip.dart b/mnemo_cards_common/lib/src/dtos/packs/pack_tip.dart new file mode 100644 index 0000000..6b333c5 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/packs/pack_tip.dart @@ -0,0 +1,105 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; + +part 'pack_tip.g.dart'; + +/// Actions for cached packs +/// Update action +@JsonSerializable() +@CopyWith() +class PackTip { + @JsonKey(unknownEnumValue: PackTipType.unknown) + final PackTipType type; + final PackTipPosition position; + final String? bgColor; + + const PackTip({ + required this.type, + required this.position, + required this.bgColor, + }); + + factory PackTip.fromJson(Map json) { + final type = _$PackTipFromJson(json).type; + switch (type) { + case PackTipType.asset: + return AssetPackTip.fromJson(json); + case PackTipType.base64: + return Base64PackTip.fromJson(json); + case PackTipType.text: + return TextPackTip.fromJson(json); + case PackTipType.unknown: + return _$PackTipFromJson(json); + } + } + + Map toJson() => _$PackTipToJson(this); +} + +@JsonSerializable() +@CopyWith() +class AssetPackTip extends PackTip { + String asset; + + AssetPackTip( + this.asset, { + super.position = PackTipPosition.fullRight, + super.type = PackTipType.asset, + super.bgColor = null, + }); + + factory AssetPackTip.fromJson(Map json) => + _$AssetPackTipFromJson(json); + + Map toJson() => _$AssetPackTipToJson(this); +} + +@JsonSerializable() +@CopyWith() +class Base64PackTip extends PackTip { + String base64; + + Base64PackTip( + this.base64, { + super.position = PackTipPosition.fullRight, + super.type = PackTipType.base64, + super.bgColor = null, + }); + + factory Base64PackTip.fromJson(Map json) => + _$Base64PackTipFromJson(json); + + Map toJson() => _$Base64PackTipToJson(this); +} + +@JsonSerializable() +@CopyWith() +class TextPackTip extends PackTip { + String text; + + TextPackTip( + this.text, { + super.position = PackTipPosition.fullRight, + super.type = PackTipType.text, + super.bgColor = null, + }); + + factory TextPackTip.fromJson(Map json) => + _$TextPackTipFromJson(json); + + Map toJson() => _$TextPackTipToJson(this); +} + +enum PackTipType { + asset, + base64, + text, + unknown, +} + +enum PackTipPosition { + topRight, + fullRight, + bottomRight, + unknown, +} diff --git a/mnemo_cards_common/lib/src/dtos/packs/pack_tip.g.dart b/mnemo_cards_common/lib/src/dtos/packs/pack_tip.g.dart new file mode 100644 index 0000000..8344bc3 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/packs/pack_tip.g.dart @@ -0,0 +1,413 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'pack_tip.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$PackTipCWProxy { + PackTip type(PackTipType type); + + PackTip position(PackTipPosition position); + + PackTip bgColor(String? bgColor); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `PackTip(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// PackTip(...).copyWith(id: 12, name: "My name") + /// ```` + PackTip call({ + PackTipType? type, + PackTipPosition? position, + String? bgColor, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfPackTip.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfPackTip.copyWith.fieldName(...)` +class _$PackTipCWProxyImpl implements _$PackTipCWProxy { + const _$PackTipCWProxyImpl(this._value); + + final PackTip _value; + + @override + PackTip type(PackTipType type) => this(type: type); + + @override + PackTip position(PackTipPosition position) => this(position: position); + + @override + PackTip bgColor(String? bgColor) => this(bgColor: bgColor); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `PackTip(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// PackTip(...).copyWith(id: 12, name: "My name") + /// ```` + PackTip call({ + Object? type = const $CopyWithPlaceholder(), + Object? position = const $CopyWithPlaceholder(), + Object? bgColor = const $CopyWithPlaceholder(), + }) { + return PackTip( + type: type == const $CopyWithPlaceholder() || type == null + ? _value.type + // ignore: cast_nullable_to_non_nullable + : type as PackTipType, + position: position == const $CopyWithPlaceholder() || position == null + ? _value.position + // ignore: cast_nullable_to_non_nullable + : position as PackTipPosition, + bgColor: bgColor == const $CopyWithPlaceholder() + ? _value.bgColor + // ignore: cast_nullable_to_non_nullable + : bgColor as String?, + ); + } +} + +extension $PackTipCopyWith on PackTip { + /// Returns a callable class that can be used as follows: `instanceOfPackTip.copyWith(...)` or like so:`instanceOfPackTip.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$PackTipCWProxy get copyWith => _$PackTipCWProxyImpl(this); +} + +abstract class _$AssetPackTipCWProxy { + AssetPackTip asset(String asset); + + AssetPackTip position(PackTipPosition position); + + AssetPackTip type(PackTipType type); + + AssetPackTip bgColor(String? bgColor); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `AssetPackTip(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// AssetPackTip(...).copyWith(id: 12, name: "My name") + /// ```` + AssetPackTip call({ + String? asset, + PackTipPosition? position, + PackTipType? type, + String? bgColor, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfAssetPackTip.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfAssetPackTip.copyWith.fieldName(...)` +class _$AssetPackTipCWProxyImpl implements _$AssetPackTipCWProxy { + const _$AssetPackTipCWProxyImpl(this._value); + + final AssetPackTip _value; + + @override + AssetPackTip asset(String asset) => this(asset: asset); + + @override + AssetPackTip position(PackTipPosition position) => this(position: position); + + @override + AssetPackTip type(PackTipType type) => this(type: type); + + @override + AssetPackTip bgColor(String? bgColor) => this(bgColor: bgColor); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `AssetPackTip(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// AssetPackTip(...).copyWith(id: 12, name: "My name") + /// ```` + AssetPackTip call({ + Object? asset = const $CopyWithPlaceholder(), + Object? position = const $CopyWithPlaceholder(), + Object? type = const $CopyWithPlaceholder(), + Object? bgColor = const $CopyWithPlaceholder(), + }) { + return AssetPackTip( + asset == const $CopyWithPlaceholder() || asset == null + ? _value.asset + // ignore: cast_nullable_to_non_nullable + : asset as String, + position: position == const $CopyWithPlaceholder() || position == null + ? _value.position + // ignore: cast_nullable_to_non_nullable + : position as PackTipPosition, + type: type == const $CopyWithPlaceholder() || type == null + ? _value.type + // ignore: cast_nullable_to_non_nullable + : type as PackTipType, + bgColor: bgColor == const $CopyWithPlaceholder() + ? _value.bgColor + // ignore: cast_nullable_to_non_nullable + : bgColor as String?, + ); + } +} + +extension $AssetPackTipCopyWith on AssetPackTip { + /// Returns a callable class that can be used as follows: `instanceOfAssetPackTip.copyWith(...)` or like so:`instanceOfAssetPackTip.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$AssetPackTipCWProxy get copyWith => _$AssetPackTipCWProxyImpl(this); +} + +abstract class _$Base64PackTipCWProxy { + Base64PackTip base64(String base64); + + Base64PackTip position(PackTipPosition position); + + Base64PackTip type(PackTipType type); + + Base64PackTip bgColor(String? bgColor); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `Base64PackTip(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// Base64PackTip(...).copyWith(id: 12, name: "My name") + /// ```` + Base64PackTip call({ + String? base64, + PackTipPosition? position, + PackTipType? type, + String? bgColor, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfBase64PackTip.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfBase64PackTip.copyWith.fieldName(...)` +class _$Base64PackTipCWProxyImpl implements _$Base64PackTipCWProxy { + const _$Base64PackTipCWProxyImpl(this._value); + + final Base64PackTip _value; + + @override + Base64PackTip base64(String base64) => this(base64: base64); + + @override + Base64PackTip position(PackTipPosition position) => this(position: position); + + @override + Base64PackTip type(PackTipType type) => this(type: type); + + @override + Base64PackTip bgColor(String? bgColor) => this(bgColor: bgColor); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `Base64PackTip(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// Base64PackTip(...).copyWith(id: 12, name: "My name") + /// ```` + Base64PackTip call({ + Object? base64 = const $CopyWithPlaceholder(), + Object? position = const $CopyWithPlaceholder(), + Object? type = const $CopyWithPlaceholder(), + Object? bgColor = const $CopyWithPlaceholder(), + }) { + return Base64PackTip( + base64 == const $CopyWithPlaceholder() || base64 == null + ? _value.base64 + // ignore: cast_nullable_to_non_nullable + : base64 as String, + position: position == const $CopyWithPlaceholder() || position == null + ? _value.position + // ignore: cast_nullable_to_non_nullable + : position as PackTipPosition, + type: type == const $CopyWithPlaceholder() || type == null + ? _value.type + // ignore: cast_nullable_to_non_nullable + : type as PackTipType, + bgColor: bgColor == const $CopyWithPlaceholder() + ? _value.bgColor + // ignore: cast_nullable_to_non_nullable + : bgColor as String?, + ); + } +} + +extension $Base64PackTipCopyWith on Base64PackTip { + /// Returns a callable class that can be used as follows: `instanceOfBase64PackTip.copyWith(...)` or like so:`instanceOfBase64PackTip.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$Base64PackTipCWProxy get copyWith => _$Base64PackTipCWProxyImpl(this); +} + +abstract class _$TextPackTipCWProxy { + TextPackTip text(String text); + + TextPackTip position(PackTipPosition position); + + TextPackTip type(PackTipType type); + + TextPackTip bgColor(String? bgColor); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TextPackTip(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// TextPackTip(...).copyWith(id: 12, name: "My name") + /// ```` + TextPackTip call({ + String? text, + PackTipPosition? position, + PackTipType? type, + String? bgColor, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfTextPackTip.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfTextPackTip.copyWith.fieldName(...)` +class _$TextPackTipCWProxyImpl implements _$TextPackTipCWProxy { + const _$TextPackTipCWProxyImpl(this._value); + + final TextPackTip _value; + + @override + TextPackTip text(String text) => this(text: text); + + @override + TextPackTip position(PackTipPosition position) => this(position: position); + + @override + TextPackTip type(PackTipType type) => this(type: type); + + @override + TextPackTip bgColor(String? bgColor) => this(bgColor: bgColor); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TextPackTip(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// TextPackTip(...).copyWith(id: 12, name: "My name") + /// ```` + TextPackTip call({ + Object? text = const $CopyWithPlaceholder(), + Object? position = const $CopyWithPlaceholder(), + Object? type = const $CopyWithPlaceholder(), + Object? bgColor = const $CopyWithPlaceholder(), + }) { + return TextPackTip( + text == const $CopyWithPlaceholder() || text == null + ? _value.text + // ignore: cast_nullable_to_non_nullable + : text as String, + position: position == const $CopyWithPlaceholder() || position == null + ? _value.position + // ignore: cast_nullable_to_non_nullable + : position as PackTipPosition, + type: type == const $CopyWithPlaceholder() || type == null + ? _value.type + // ignore: cast_nullable_to_non_nullable + : type as PackTipType, + bgColor: bgColor == const $CopyWithPlaceholder() + ? _value.bgColor + // ignore: cast_nullable_to_non_nullable + : bgColor as String?, + ); + } +} + +extension $TextPackTipCopyWith on TextPackTip { + /// Returns a callable class that can be used as follows: `instanceOfTextPackTip.copyWith(...)` or like so:`instanceOfTextPackTip.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$TextPackTipCWProxy get copyWith => _$TextPackTipCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +PackTip _$PackTipFromJson(Map json) => PackTip( + type: $enumDecode(_$PackTipTypeEnumMap, json['type'], + unknownValue: PackTipType.unknown), + position: $enumDecode(_$PackTipPositionEnumMap, json['position']), + bgColor: json['bgColor'] as String?, + ); + +Map _$PackTipToJson(PackTip instance) => { + 'type': _$PackTipTypeEnumMap[instance.type]!, + 'position': _$PackTipPositionEnumMap[instance.position]!, + 'bgColor': instance.bgColor, + }; + +const _$PackTipTypeEnumMap = { + PackTipType.asset: 'asset', + PackTipType.base64: 'base64', + PackTipType.text: 'text', + PackTipType.unknown: 'unknown', +}; + +const _$PackTipPositionEnumMap = { + PackTipPosition.topRight: 'topRight', + PackTipPosition.fullRight: 'fullRight', + PackTipPosition.bottomRight: 'bottomRight', + PackTipPosition.unknown: 'unknown', +}; + +AssetPackTip _$AssetPackTipFromJson(Map json) => AssetPackTip( + json['asset'] as String, + position: + $enumDecodeNullable(_$PackTipPositionEnumMap, json['position']) ?? + PackTipPosition.fullRight, + type: $enumDecodeNullable(_$PackTipTypeEnumMap, json['type'], + unknownValue: PackTipType.unknown) ?? + PackTipType.asset, + bgColor: json['bgColor'] as String? ?? null, + ); + +Map _$AssetPackTipToJson(AssetPackTip instance) => + { + 'type': _$PackTipTypeEnumMap[instance.type]!, + 'position': _$PackTipPositionEnumMap[instance.position]!, + 'bgColor': instance.bgColor, + 'asset': instance.asset, + }; + +Base64PackTip _$Base64PackTipFromJson(Map json) => + Base64PackTip( + json['base64'] as String, + position: + $enumDecodeNullable(_$PackTipPositionEnumMap, json['position']) ?? + PackTipPosition.fullRight, + type: $enumDecodeNullable(_$PackTipTypeEnumMap, json['type'], + unknownValue: PackTipType.unknown) ?? + PackTipType.base64, + bgColor: json['bgColor'] as String? ?? null, + ); + +Map _$Base64PackTipToJson(Base64PackTip instance) => + { + 'type': _$PackTipTypeEnumMap[instance.type]!, + 'position': _$PackTipPositionEnumMap[instance.position]!, + 'bgColor': instance.bgColor, + 'base64': instance.base64, + }; + +TextPackTip _$TextPackTipFromJson(Map json) => TextPackTip( + json['text'] as String, + position: + $enumDecodeNullable(_$PackTipPositionEnumMap, json['position']) ?? + PackTipPosition.fullRight, + type: $enumDecodeNullable(_$PackTipTypeEnumMap, json['type'], + unknownValue: PackTipType.unknown) ?? + PackTipType.text, + bgColor: json['bgColor'] as String? ?? null, + ); + +Map _$TextPackTipToJson(TextPackTip instance) => + { + 'type': _$PackTipTypeEnumMap[instance.type]!, + 'position': _$PackTipPositionEnumMap[instance.position]!, + 'bgColor': instance.bgColor, + 'text': instance.text, + }; diff --git a/mnemo_cards_common/lib/src/dtos/payment/export.dart b/mnemo_cards_common/lib/src/dtos/payment/export.dart new file mode 100644 index 0000000..d48c494 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/payment/export.dart @@ -0,0 +1,3 @@ +export 'payment_dto.dart'; +export 'product_type.dart'; +export 'yookassa_payment_dto.dart'; \ No newline at end of file diff --git a/mnemo_cards_common/lib/src/dtos/payment/payment_dto.dart b/mnemo_cards_common/lib/src/dtos/payment/payment_dto.dart new file mode 100644 index 0000000..5d242cb --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/payment/payment_dto.dart @@ -0,0 +1,87 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'product_type.dart'; + +part 'payment_dto.g.dart'; + +@JsonSerializable() +@CopyWith() +class PaymentDto { + final String amount; + final String currency; + final DateTime date; + @JsonKey(unknownEnumValue: PaymentStatus.unknown) + final PaymentStatus status; + @JsonKey(unknownEnumValue: PaymentSystem.unknown) + final PaymentSystem paymentSystem; + final String? externalToken; + final String? meta; + + @deprecated + final List? packs; + @deprecated + final bool? subscription; + final List products; + + const PaymentDto({ + required this.amount, + required this.currency, + required this.status, + required this.paymentSystem, + required this.date, + required this.packs, + required this.subscription, + required this.products, + required this.externalToken, + required this.meta, + }); + + factory PaymentDto.fromJson(Map json) => + _$PaymentDtoFromJson(json); + + Map toJson() => _$PaymentDtoToJson(this); +} + +@JsonSerializable() +@CopyWith() +class MnemoCardsProductDto { + final String? id; + + final MnemoCardsProductType type; + + const MnemoCardsProductDto({ + this.id, + this.type = MnemoCardsProductType.unknown, + }); + + factory MnemoCardsProductDto.fromJson(Map json) => + _$MnemoCardsProductDtoFromJson(json); + + Map toJson() => _$MnemoCardsProductDtoToJson(this); +} + +extension MnemoCardsProductExt on MnemoCardsProductDto { + MnemoCardsProductDto toProduct() => MnemoCardsProductDto(id: id, type: type); + + bool productEquals(MnemoCardsProductDto? other) => + other is MnemoCardsProductDto && other.id == id && other.type == type; +} + +enum PaymentStatus { + created, + waiting, + succeeded, + canceled, + processed, + unknown, +} + +enum PaymentSystem { + google, + apple, + rustore, + yookassa, + promoCode, + adView, + unknown, +} diff --git a/mnemo_cards_common/lib/src/dtos/payment/payment_dto.g.dart b/mnemo_cards_common/lib/src/dtos/payment/payment_dto.g.dart new file mode 100644 index 0000000..e40d6f4 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/payment/payment_dto.g.dart @@ -0,0 +1,300 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'payment_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$PaymentDtoCWProxy { + PaymentDto amount(String amount); + + PaymentDto currency(String currency); + + PaymentDto status(PaymentStatus status); + + PaymentDto paymentSystem(PaymentSystem paymentSystem); + + PaymentDto date(DateTime date); + + PaymentDto packs(List? packs); + + PaymentDto subscription(bool? subscription); + + PaymentDto products(List products); + + PaymentDto externalToken(String? externalToken); + + PaymentDto meta(String? meta); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `PaymentDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// PaymentDto(...).copyWith(id: 12, name: "My name") + /// ```` + PaymentDto call({ + String? amount, + String? currency, + PaymentStatus? status, + PaymentSystem? paymentSystem, + DateTime? date, + List? packs, + bool? subscription, + List? products, + String? externalToken, + String? meta, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfPaymentDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfPaymentDto.copyWith.fieldName(...)` +class _$PaymentDtoCWProxyImpl implements _$PaymentDtoCWProxy { + const _$PaymentDtoCWProxyImpl(this._value); + + final PaymentDto _value; + + @override + PaymentDto amount(String amount) => this(amount: amount); + + @override + PaymentDto currency(String currency) => this(currency: currency); + + @override + PaymentDto status(PaymentStatus status) => this(status: status); + + @override + PaymentDto paymentSystem(PaymentSystem paymentSystem) => + this(paymentSystem: paymentSystem); + + @override + PaymentDto date(DateTime date) => this(date: date); + + @override + PaymentDto packs(List? packs) => this(packs: packs); + + @override + PaymentDto subscription(bool? subscription) => + this(subscription: subscription); + + @override + PaymentDto products(List products) => + this(products: products); + + @override + PaymentDto externalToken(String? externalToken) => + this(externalToken: externalToken); + + @override + PaymentDto meta(String? meta) => this(meta: meta); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `PaymentDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// PaymentDto(...).copyWith(id: 12, name: "My name") + /// ```` + PaymentDto call({ + Object? amount = const $CopyWithPlaceholder(), + Object? currency = const $CopyWithPlaceholder(), + Object? status = const $CopyWithPlaceholder(), + Object? paymentSystem = const $CopyWithPlaceholder(), + Object? date = const $CopyWithPlaceholder(), + Object? packs = const $CopyWithPlaceholder(), + Object? subscription = const $CopyWithPlaceholder(), + Object? products = const $CopyWithPlaceholder(), + Object? externalToken = const $CopyWithPlaceholder(), + Object? meta = const $CopyWithPlaceholder(), + }) { + return PaymentDto( + amount: amount == const $CopyWithPlaceholder() || amount == null + ? _value.amount + // ignore: cast_nullable_to_non_nullable + : amount as String, + currency: currency == const $CopyWithPlaceholder() || currency == null + ? _value.currency + // ignore: cast_nullable_to_non_nullable + : currency as String, + status: status == const $CopyWithPlaceholder() || status == null + ? _value.status + // ignore: cast_nullable_to_non_nullable + : status as PaymentStatus, + paymentSystem: + paymentSystem == const $CopyWithPlaceholder() || paymentSystem == null + ? _value.paymentSystem + // ignore: cast_nullable_to_non_nullable + : paymentSystem as PaymentSystem, + date: date == const $CopyWithPlaceholder() || date == null + ? _value.date + // ignore: cast_nullable_to_non_nullable + : date as DateTime, + packs: packs == const $CopyWithPlaceholder() + ? _value.packs + // ignore: cast_nullable_to_non_nullable + : packs as List?, + subscription: subscription == const $CopyWithPlaceholder() + ? _value.subscription + // ignore: cast_nullable_to_non_nullable + : subscription as bool?, + products: products == const $CopyWithPlaceholder() || products == null + ? _value.products + // ignore: cast_nullable_to_non_nullable + : products as List, + externalToken: externalToken == const $CopyWithPlaceholder() + ? _value.externalToken + // ignore: cast_nullable_to_non_nullable + : externalToken as String?, + meta: meta == const $CopyWithPlaceholder() + ? _value.meta + // ignore: cast_nullable_to_non_nullable + : meta as String?, + ); + } +} + +extension $PaymentDtoCopyWith on PaymentDto { + /// Returns a callable class that can be used as follows: `instanceOfPaymentDto.copyWith(...)` or like so:`instanceOfPaymentDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$PaymentDtoCWProxy get copyWith => _$PaymentDtoCWProxyImpl(this); +} + +abstract class _$MnemoCardsProductDtoCWProxy { + MnemoCardsProductDto id(String? id); + + MnemoCardsProductDto type(MnemoCardsProductType type); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `MnemoCardsProductDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// MnemoCardsProductDto(...).copyWith(id: 12, name: "My name") + /// ```` + MnemoCardsProductDto call({ + String? id, + MnemoCardsProductType? type, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfMnemoCardsProductDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfMnemoCardsProductDto.copyWith.fieldName(...)` +class _$MnemoCardsProductDtoCWProxyImpl + implements _$MnemoCardsProductDtoCWProxy { + const _$MnemoCardsProductDtoCWProxyImpl(this._value); + + final MnemoCardsProductDto _value; + + @override + MnemoCardsProductDto id(String? id) => this(id: id); + + @override + MnemoCardsProductDto type(MnemoCardsProductType type) => this(type: type); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `MnemoCardsProductDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// MnemoCardsProductDto(...).copyWith(id: 12, name: "My name") + /// ```` + MnemoCardsProductDto call({ + Object? id = const $CopyWithPlaceholder(), + Object? type = const $CopyWithPlaceholder(), + }) { + return MnemoCardsProductDto( + id: id == const $CopyWithPlaceholder() + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as String?, + type: type == const $CopyWithPlaceholder() || type == null + ? _value.type + // ignore: cast_nullable_to_non_nullable + : type as MnemoCardsProductType, + ); + } +} + +extension $MnemoCardsProductDtoCopyWith on MnemoCardsProductDto { + /// Returns a callable class that can be used as follows: `instanceOfMnemoCardsProductDto.copyWith(...)` or like so:`instanceOfMnemoCardsProductDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$MnemoCardsProductDtoCWProxy get copyWith => + _$MnemoCardsProductDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +PaymentDto _$PaymentDtoFromJson(Map json) => PaymentDto( + amount: json['amount'] as String, + currency: json['currency'] as String, + status: $enumDecode(_$PaymentStatusEnumMap, json['status'], + unknownValue: PaymentStatus.unknown), + paymentSystem: $enumDecode(_$PaymentSystemEnumMap, json['paymentSystem'], + unknownValue: PaymentSystem.unknown), + date: DateTime.parse(json['date'] as String), + packs: + (json['packs'] as List?)?.map((e) => e as String).toList(), + subscription: json['subscription'] as bool?, + products: (json['products'] as List) + .map((e) => MnemoCardsProductDto.fromJson(e as Map)) + .toList(), + externalToken: json['externalToken'] as String?, + meta: json['meta'] as String?, + ); + +Map _$PaymentDtoToJson(PaymentDto instance) => + { + 'amount': instance.amount, + 'currency': instance.currency, + 'date': instance.date.toIso8601String(), + 'status': _$PaymentStatusEnumMap[instance.status]!, + 'paymentSystem': _$PaymentSystemEnumMap[instance.paymentSystem]!, + 'externalToken': instance.externalToken, + 'meta': instance.meta, + 'packs': instance.packs, + 'subscription': instance.subscription, + 'products': instance.products, + }; + +const _$PaymentStatusEnumMap = { + PaymentStatus.created: 'created', + PaymentStatus.waiting: 'waiting', + PaymentStatus.succeeded: 'succeeded', + PaymentStatus.canceled: 'canceled', + PaymentStatus.processed: 'processed', + PaymentStatus.unknown: 'unknown', +}; + +const _$PaymentSystemEnumMap = { + PaymentSystem.google: 'google', + PaymentSystem.apple: 'apple', + PaymentSystem.rustore: 'rustore', + PaymentSystem.yookassa: 'yookassa', + PaymentSystem.promoCode: 'promoCode', + PaymentSystem.adView: 'adView', + PaymentSystem.unknown: 'unknown', +}; + +MnemoCardsProductDto _$MnemoCardsProductDtoFromJson( + Map json) => + MnemoCardsProductDto( + id: json['id'] as String?, + type: $enumDecodeNullable(_$MnemoCardsProductTypeEnumMap, json['type']) ?? + MnemoCardsProductType.unknown, + ); + +Map _$MnemoCardsProductDtoToJson( + MnemoCardsProductDto instance) => + { + 'id': instance.id, + 'type': _$MnemoCardsProductTypeEnumMap[instance.type]!, + }; + +const _$MnemoCardsProductTypeEnumMap = { + MnemoCardsProductType.pack: 'pack', + MnemoCardsProductType.subscription: 'subscription', + MnemoCardsProductType.discount: 'discount', + MnemoCardsProductType.game: 'game', + MnemoCardsProductType.unknown: 'unknown', +}; diff --git a/mnemo_cards_common/lib/src/dtos/payment/product_type.dart b/mnemo_cards_common/lib/src/dtos/payment/product_type.dart new file mode 100644 index 0000000..df2b12f --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/payment/product_type.dart @@ -0,0 +1,22 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:mnemo_cards_common/mnemo_cards_common.dart'; + +part 'product_type.g.dart'; + +@JsonEnum(alwaysCreate: true) +enum MnemoCardsProductType { + pack, + subscription, + discount, + game, + unknown; + + factory MnemoCardsProductType.fromName(String name) => + _$MnemoCardsProductTypeEnumMap.entries + .firstWhereOrNull((entry) => entry.value == name) + ?.key ?? + MnemoCardsProductType.unknown; + + static String toName(MnemoCardsProductType type) => + _$MnemoCardsProductTypeEnumMap[type]!; +} diff --git a/mnemo_cards_common/lib/src/dtos/payment/product_type.g.dart b/mnemo_cards_common/lib/src/dtos/payment/product_type.g.dart new file mode 100644 index 0000000..d95173f --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/payment/product_type.g.dart @@ -0,0 +1,15 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'product_type.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +const _$MnemoCardsProductTypeEnumMap = { + MnemoCardsProductType.pack: 'pack', + MnemoCardsProductType.subscription: 'subscription', + MnemoCardsProductType.discount: 'discount', + MnemoCardsProductType.game: 'game', + MnemoCardsProductType.unknown: 'unknown', +}; diff --git a/mnemo_cards_common/lib/src/dtos/payment/yookassa_payment_dto.dart b/mnemo_cards_common/lib/src/dtos/payment/yookassa_payment_dto.dart new file mode 100644 index 0000000..f1abea2 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/payment/yookassa_payment_dto.dart @@ -0,0 +1,21 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; + +part 'yookassa_payment_dto.g.dart'; + +@JsonSerializable() +@CopyWith() +class YookassaPaymentDto { + final String purchaseUrl; + final String checkUrl; + + YookassaPaymentDto({ + required this.purchaseUrl, + required this.checkUrl, + }); + + factory YookassaPaymentDto.fromJson(Map json) => + _$YookassaPaymentDtoFromJson(json); + + Map toJson() => _$YookassaPaymentDtoToJson(this); +} diff --git a/mnemo_cards_common/lib/src/dtos/payment/yookassa_payment_dto.g.dart b/mnemo_cards_common/lib/src/dtos/payment/yookassa_payment_dto.g.dart new file mode 100644 index 0000000..2a83615 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/payment/yookassa_payment_dto.g.dart @@ -0,0 +1,86 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'yookassa_payment_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$YookassaPaymentDtoCWProxy { + YookassaPaymentDto purchaseUrl(String purchaseUrl); + + YookassaPaymentDto checkUrl(String checkUrl); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `YookassaPaymentDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// YookassaPaymentDto(...).copyWith(id: 12, name: "My name") + /// ```` + YookassaPaymentDto call({ + String? purchaseUrl, + String? checkUrl, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfYookassaPaymentDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfYookassaPaymentDto.copyWith.fieldName(...)` +class _$YookassaPaymentDtoCWProxyImpl implements _$YookassaPaymentDtoCWProxy { + const _$YookassaPaymentDtoCWProxyImpl(this._value); + + final YookassaPaymentDto _value; + + @override + YookassaPaymentDto purchaseUrl(String purchaseUrl) => + this(purchaseUrl: purchaseUrl); + + @override + YookassaPaymentDto checkUrl(String checkUrl) => this(checkUrl: checkUrl); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `YookassaPaymentDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// YookassaPaymentDto(...).copyWith(id: 12, name: "My name") + /// ```` + YookassaPaymentDto call({ + Object? purchaseUrl = const $CopyWithPlaceholder(), + Object? checkUrl = const $CopyWithPlaceholder(), + }) { + return YookassaPaymentDto( + purchaseUrl: + purchaseUrl == const $CopyWithPlaceholder() || purchaseUrl == null + ? _value.purchaseUrl + // ignore: cast_nullable_to_non_nullable + : purchaseUrl as String, + checkUrl: checkUrl == const $CopyWithPlaceholder() || checkUrl == null + ? _value.checkUrl + // ignore: cast_nullable_to_non_nullable + : checkUrl as String, + ); + } +} + +extension $YookassaPaymentDtoCopyWith on YookassaPaymentDto { + /// Returns a callable class that can be used as follows: `instanceOfYookassaPaymentDto.copyWith(...)` or like so:`instanceOfYookassaPaymentDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$YookassaPaymentDtoCWProxy get copyWith => + _$YookassaPaymentDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +YookassaPaymentDto _$YookassaPaymentDtoFromJson(Map json) => + YookassaPaymentDto( + purchaseUrl: json['purchaseUrl'] as String, + checkUrl: json['checkUrl'] as String, + ); + +Map _$YookassaPaymentDtoToJson(YookassaPaymentDto instance) => + { + 'purchaseUrl': instance.purchaseUrl, + 'checkUrl': instance.checkUrl, + }; diff --git a/mnemo_cards_common/lib/src/dtos/promo_codes/promo_codes_campaign_dto.dart b/mnemo_cards_common/lib/src/dtos/promo_codes/promo_codes_campaign_dto.dart new file mode 100644 index 0000000..f228479 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/promo_codes/promo_codes_campaign_dto.dart @@ -0,0 +1,51 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; + +import '../payment/payment_dto.dart'; + +part 'promo_codes_campaign_dto.g.dart'; + +@JsonSerializable() +@CopyWith() +class PromoCodesCampaignDto { + final int? id; + final List products; + final int activationsPerCode; + final int activationsPerUser; + final List? promoCodes; + final List tags; + final int generationSize; + final DateTime start; + final DateTime finish; + final PromoCodeCampaignStatus status; + final String? name; + final String template; + + const PromoCodesCampaignDto({ + required this.products, + required this.activationsPerCode, + required this.activationsPerUser, + required this.generationSize, + required this.start, + required this.finish, + required this.status, + required this.template, + required this.tags, + this.name, + this.id, + this.promoCodes, + }); + + factory PromoCodesCampaignDto.fromJson(Map json) => + _$PromoCodesCampaignDtoFromJson(json); + + Map toJson() => _$PromoCodesCampaignDtoToJson(this); +} + +enum PromoCodeCampaignStatus { + created, + preparing, + ready, + active, + disabled, +} diff --git a/mnemo_cards_common/lib/src/dtos/promo_codes/promo_codes_campaign_dto.g.dart b/mnemo_cards_common/lib/src/dtos/promo_codes/promo_codes_campaign_dto.g.dart new file mode 100644 index 0000000..786ae97 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/promo_codes/promo_codes_campaign_dto.g.dart @@ -0,0 +1,238 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'promo_codes_campaign_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$PromoCodesCampaignDtoCWProxy { + PromoCodesCampaignDto products(List products); + + PromoCodesCampaignDto activationsPerCode(int activationsPerCode); + + PromoCodesCampaignDto activationsPerUser(int activationsPerUser); + + PromoCodesCampaignDto generationSize(int generationSize); + + PromoCodesCampaignDto start(DateTime start); + + PromoCodesCampaignDto finish(DateTime finish); + + PromoCodesCampaignDto status(PromoCodeCampaignStatus status); + + PromoCodesCampaignDto template(String template); + + PromoCodesCampaignDto tags(List tags); + + PromoCodesCampaignDto name(String? name); + + PromoCodesCampaignDto id(int? id); + + PromoCodesCampaignDto promoCodes(List? promoCodes); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `PromoCodesCampaignDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// PromoCodesCampaignDto(...).copyWith(id: 12, name: "My name") + /// ```` + PromoCodesCampaignDto call({ + List? products, + int? activationsPerCode, + int? activationsPerUser, + int? generationSize, + DateTime? start, + DateTime? finish, + PromoCodeCampaignStatus? status, + String? template, + List? tags, + String? name, + int? id, + List? promoCodes, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfPromoCodesCampaignDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfPromoCodesCampaignDto.copyWith.fieldName(...)` +class _$PromoCodesCampaignDtoCWProxyImpl + implements _$PromoCodesCampaignDtoCWProxy { + const _$PromoCodesCampaignDtoCWProxyImpl(this._value); + + final PromoCodesCampaignDto _value; + + @override + PromoCodesCampaignDto products(List products) => + this(products: products); + + @override + PromoCodesCampaignDto activationsPerCode(int activationsPerCode) => + this(activationsPerCode: activationsPerCode); + + @override + PromoCodesCampaignDto activationsPerUser(int activationsPerUser) => + this(activationsPerUser: activationsPerUser); + + @override + PromoCodesCampaignDto generationSize(int generationSize) => + this(generationSize: generationSize); + + @override + PromoCodesCampaignDto start(DateTime start) => this(start: start); + + @override + PromoCodesCampaignDto finish(DateTime finish) => this(finish: finish); + + @override + PromoCodesCampaignDto status(PromoCodeCampaignStatus status) => + this(status: status); + + @override + PromoCodesCampaignDto template(String template) => this(template: template); + + @override + PromoCodesCampaignDto tags(List tags) => this(tags: tags); + + @override + PromoCodesCampaignDto name(String? name) => this(name: name); + + @override + PromoCodesCampaignDto id(int? id) => this(id: id); + + @override + PromoCodesCampaignDto promoCodes(List? promoCodes) => + this(promoCodes: promoCodes); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `PromoCodesCampaignDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// PromoCodesCampaignDto(...).copyWith(id: 12, name: "My name") + /// ```` + PromoCodesCampaignDto call({ + Object? products = const $CopyWithPlaceholder(), + Object? activationsPerCode = const $CopyWithPlaceholder(), + Object? activationsPerUser = const $CopyWithPlaceholder(), + Object? generationSize = const $CopyWithPlaceholder(), + Object? start = const $CopyWithPlaceholder(), + Object? finish = const $CopyWithPlaceholder(), + Object? status = const $CopyWithPlaceholder(), + Object? template = const $CopyWithPlaceholder(), + Object? tags = const $CopyWithPlaceholder(), + Object? name = const $CopyWithPlaceholder(), + Object? id = const $CopyWithPlaceholder(), + Object? promoCodes = const $CopyWithPlaceholder(), + }) { + return PromoCodesCampaignDto( + products: products == const $CopyWithPlaceholder() || products == null + ? _value.products + // ignore: cast_nullable_to_non_nullable + : products as List, + activationsPerCode: activationsPerCode == const $CopyWithPlaceholder() || + activationsPerCode == null + ? _value.activationsPerCode + // ignore: cast_nullable_to_non_nullable + : activationsPerCode as int, + activationsPerUser: activationsPerUser == const $CopyWithPlaceholder() || + activationsPerUser == null + ? _value.activationsPerUser + // ignore: cast_nullable_to_non_nullable + : activationsPerUser as int, + generationSize: generationSize == const $CopyWithPlaceholder() || + generationSize == null + ? _value.generationSize + // ignore: cast_nullable_to_non_nullable + : generationSize as int, + start: start == const $CopyWithPlaceholder() || start == null + ? _value.start + // ignore: cast_nullable_to_non_nullable + : start as DateTime, + finish: finish == const $CopyWithPlaceholder() || finish == null + ? _value.finish + // ignore: cast_nullable_to_non_nullable + : finish as DateTime, + status: status == const $CopyWithPlaceholder() || status == null + ? _value.status + // ignore: cast_nullable_to_non_nullable + : status as PromoCodeCampaignStatus, + template: template == const $CopyWithPlaceholder() || template == null + ? _value.template + // ignore: cast_nullable_to_non_nullable + : template as String, + tags: tags == const $CopyWithPlaceholder() || tags == null + ? _value.tags + // ignore: cast_nullable_to_non_nullable + : tags as List, + name: name == const $CopyWithPlaceholder() + ? _value.name + // ignore: cast_nullable_to_non_nullable + : name as String?, + id: id == const $CopyWithPlaceholder() + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as int?, + promoCodes: promoCodes == const $CopyWithPlaceholder() + ? _value.promoCodes + // ignore: cast_nullable_to_non_nullable + : promoCodes as List?, + ); + } +} + +extension $PromoCodesCampaignDtoCopyWith on PromoCodesCampaignDto { + /// Returns a callable class that can be used as follows: `instanceOfPromoCodesCampaignDto.copyWith(...)` or like so:`instanceOfPromoCodesCampaignDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$PromoCodesCampaignDtoCWProxy get copyWith => + _$PromoCodesCampaignDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +PromoCodesCampaignDto _$PromoCodesCampaignDtoFromJson( + Map json) => + PromoCodesCampaignDto( + products: (json['products'] as List) + .map((e) => MnemoCardsProductDto.fromJson(e as Map)) + .toList(), + activationsPerCode: json['activationsPerCode'] as int, + activationsPerUser: json['activationsPerUser'] as int, + generationSize: json['generationSize'] as int, + start: DateTime.parse(json['start'] as String), + finish: DateTime.parse(json['finish'] as String), + status: $enumDecode(_$PromoCodeCampaignStatusEnumMap, json['status']), + template: json['template'] as String, + tags: (json['tags'] as List).map((e) => e as String).toList(), + name: json['name'] as String?, + id: json['id'] as int?, + promoCodes: (json['promoCodes'] as List?) + ?.map((e) => e as String) + .toList(), + ); + +Map _$PromoCodesCampaignDtoToJson( + PromoCodesCampaignDto instance) => + { + 'id': instance.id, + 'products': instance.products, + 'activationsPerCode': instance.activationsPerCode, + 'activationsPerUser': instance.activationsPerUser, + 'promoCodes': instance.promoCodes, + 'tags': instance.tags, + 'generationSize': instance.generationSize, + 'start': instance.start.toIso8601String(), + 'finish': instance.finish.toIso8601String(), + 'status': _$PromoCodeCampaignStatusEnumMap[instance.status]!, + 'name': instance.name, + 'template': instance.template, + }; + +const _$PromoCodeCampaignStatusEnumMap = { + PromoCodeCampaignStatus.created: 'created', + PromoCodeCampaignStatus.preparing: 'preparing', + PromoCodeCampaignStatus.ready: 'ready', + PromoCodeCampaignStatus.active: 'active', + PromoCodeCampaignStatus.disabled: 'disabled', +}; diff --git a/mnemo_cards_common/lib/src/dtos/subscription/subscription_features.dart b/mnemo_cards_common/lib/src/dtos/subscription/subscription_features.dart new file mode 100644 index 0000000..0808c79 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/subscription/subscription_features.dart @@ -0,0 +1,5 @@ +enum SubscriptionFeatureEnum { + ads, + packs, + unknown, +} diff --git a/mnemo_cards_common/lib/src/dtos/subscription/subscription_plan_admin_dto.dart b/mnemo_cards_common/lib/src/dtos/subscription/subscription_plan_admin_dto.dart new file mode 100644 index 0000000..c7488ae --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/subscription/subscription_plan_admin_dto.dart @@ -0,0 +1,39 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:mnemo_cards_common/mnemo_cards_common.dart'; + + +part 'subscription_plan_admin_dto.g.dart'; + +@JsonSerializable() +@CopyWith() +class SubscriptionPlanAdminDto implements MnemoCardsProductDto { + final String? id; + final SubscriptionPlanUIDto ui; + final String price; + final String currency; + final int durationDays; + final List features; + final PaymentSystem paymentSystem; + final String? paymentId; + + const SubscriptionPlanAdminDto({ + this.id, + required this.ui, + required this.price, + required this.currency, + required this.durationDays, + required this.features, + required this.paymentSystem, + required this.paymentId, + }); + + factory SubscriptionPlanAdminDto.fromJson(Map json) => + _$SubscriptionPlanAdminDtoFromJson(json); + + Map toJson() => _$SubscriptionPlanAdminDtoToJson(this); + + @override + MnemoCardsProductType get type => MnemoCardsProductType.subscription; +} + diff --git a/mnemo_cards_common/lib/src/dtos/subscription/subscription_plan_admin_dto.g.dart b/mnemo_cards_common/lib/src/dtos/subscription/subscription_plan_admin_dto.g.dart new file mode 100644 index 0000000..1f7c399 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/subscription/subscription_plan_admin_dto.g.dart @@ -0,0 +1,192 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'subscription_plan_admin_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$SubscriptionPlanAdminDtoCWProxy { + SubscriptionPlanAdminDto id(String? id); + + SubscriptionPlanAdminDto ui(SubscriptionPlanUIDto ui); + + SubscriptionPlanAdminDto price(String price); + + SubscriptionPlanAdminDto currency(String currency); + + SubscriptionPlanAdminDto durationDays(int durationDays); + + SubscriptionPlanAdminDto features(List features); + + SubscriptionPlanAdminDto paymentSystem(PaymentSystem paymentSystem); + + SubscriptionPlanAdminDto paymentId(String? paymentId); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SubscriptionPlanAdminDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// SubscriptionPlanAdminDto(...).copyWith(id: 12, name: "My name") + /// ```` + SubscriptionPlanAdminDto call({ + String? id, + SubscriptionPlanUIDto? ui, + String? price, + String? currency, + int? durationDays, + List? features, + PaymentSystem? paymentSystem, + String? paymentId, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfSubscriptionPlanAdminDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfSubscriptionPlanAdminDto.copyWith.fieldName(...)` +class _$SubscriptionPlanAdminDtoCWProxyImpl + implements _$SubscriptionPlanAdminDtoCWProxy { + const _$SubscriptionPlanAdminDtoCWProxyImpl(this._value); + + final SubscriptionPlanAdminDto _value; + + @override + SubscriptionPlanAdminDto id(String? id) => this(id: id); + + @override + SubscriptionPlanAdminDto ui(SubscriptionPlanUIDto ui) => this(ui: ui); + + @override + SubscriptionPlanAdminDto price(String price) => this(price: price); + + @override + SubscriptionPlanAdminDto currency(String currency) => + this(currency: currency); + + @override + SubscriptionPlanAdminDto durationDays(int durationDays) => + this(durationDays: durationDays); + + @override + SubscriptionPlanAdminDto features(List features) => + this(features: features); + + @override + SubscriptionPlanAdminDto paymentSystem(PaymentSystem paymentSystem) => + this(paymentSystem: paymentSystem); + + @override + SubscriptionPlanAdminDto paymentId(String? paymentId) => + this(paymentId: paymentId); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SubscriptionPlanAdminDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// SubscriptionPlanAdminDto(...).copyWith(id: 12, name: "My name") + /// ```` + SubscriptionPlanAdminDto call({ + Object? id = const $CopyWithPlaceholder(), + Object? ui = const $CopyWithPlaceholder(), + Object? price = const $CopyWithPlaceholder(), + Object? currency = const $CopyWithPlaceholder(), + Object? durationDays = const $CopyWithPlaceholder(), + Object? features = const $CopyWithPlaceholder(), + Object? paymentSystem = const $CopyWithPlaceholder(), + Object? paymentId = const $CopyWithPlaceholder(), + }) { + return SubscriptionPlanAdminDto( + id: id == const $CopyWithPlaceholder() + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as String?, + ui: ui == const $CopyWithPlaceholder() || ui == null + ? _value.ui + // ignore: cast_nullable_to_non_nullable + : ui as SubscriptionPlanUIDto, + price: price == const $CopyWithPlaceholder() || price == null + ? _value.price + // ignore: cast_nullable_to_non_nullable + : price as String, + currency: currency == const $CopyWithPlaceholder() || currency == null + ? _value.currency + // ignore: cast_nullable_to_non_nullable + : currency as String, + durationDays: + durationDays == const $CopyWithPlaceholder() || durationDays == null + ? _value.durationDays + // ignore: cast_nullable_to_non_nullable + : durationDays as int, + features: features == const $CopyWithPlaceholder() || features == null + ? _value.features + // ignore: cast_nullable_to_non_nullable + : features as List, + paymentSystem: + paymentSystem == const $CopyWithPlaceholder() || paymentSystem == null + ? _value.paymentSystem + // ignore: cast_nullable_to_non_nullable + : paymentSystem as PaymentSystem, + paymentId: paymentId == const $CopyWithPlaceholder() + ? _value.paymentId + // ignore: cast_nullable_to_non_nullable + : paymentId as String?, + ); + } +} + +extension $SubscriptionPlanAdminDtoCopyWith on SubscriptionPlanAdminDto { + /// Returns a callable class that can be used as follows: `instanceOfSubscriptionPlanAdminDto.copyWith(...)` or like so:`instanceOfSubscriptionPlanAdminDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$SubscriptionPlanAdminDtoCWProxy get copyWith => + _$SubscriptionPlanAdminDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SubscriptionPlanAdminDto _$SubscriptionPlanAdminDtoFromJson( + Map json) => + SubscriptionPlanAdminDto( + id: json['id'] as String?, + ui: SubscriptionPlanUIDto.fromJson(json['ui'] as Map), + price: json['price'] as String, + currency: json['currency'] as String, + durationDays: json['durationDays'] as int, + features: (json['features'] as List) + .map((e) => $enumDecode(_$SubscriptionFeatureEnumEnumMap, e)) + .toList(), + paymentSystem: $enumDecode(_$PaymentSystemEnumMap, json['paymentSystem']), + paymentId: json['paymentId'] as String?, + ); + +Map _$SubscriptionPlanAdminDtoToJson( + SubscriptionPlanAdminDto instance) => + { + 'id': instance.id, + 'ui': instance.ui, + 'price': instance.price, + 'currency': instance.currency, + 'durationDays': instance.durationDays, + 'features': instance.features + .map((e) => _$SubscriptionFeatureEnumEnumMap[e]!) + .toList(), + 'paymentSystem': _$PaymentSystemEnumMap[instance.paymentSystem]!, + 'paymentId': instance.paymentId, + }; + +const _$SubscriptionFeatureEnumEnumMap = { + SubscriptionFeatureEnum.ads: 'ads', + SubscriptionFeatureEnum.packs: 'packs', + SubscriptionFeatureEnum.unknown: 'unknown', +}; + +const _$PaymentSystemEnumMap = { + PaymentSystem.google: 'google', + PaymentSystem.apple: 'apple', + PaymentSystem.rustore: 'rustore', + PaymentSystem.yookassa: 'yookassa', + PaymentSystem.promoCode: 'promoCode', + PaymentSystem.adView: 'adView', + PaymentSystem.unknown: 'unknown', +}; diff --git a/mnemo_cards_common/lib/src/dtos/subscription/subscription_plan_dto.dart b/mnemo_cards_common/lib/src/dtos/subscription/subscription_plan_dto.dart new file mode 100644 index 0000000..2abae97 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/subscription/subscription_plan_dto.dart @@ -0,0 +1,100 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:mnemo_cards_common/mnemo_cards_common.dart'; + + +part 'subscription_plan_dto.g.dart'; + +@JsonSerializable() +@CopyWith() +class SubscriptionDto { + final SubscriptionPageDto? page; + final bool isActive; + final DateTime? start; + final DateTime? finish; + + SubscriptionDto({ + required this.page, + required this.isActive, + required this.start, + required this.finish, + }); + + factory SubscriptionDto.fromJson(Map json) => + _$SubscriptionDtoFromJson(json); + + Map toJson() => _$SubscriptionDtoToJson(this); +} + +@JsonSerializable() +@CopyWith() +class SubscriptionPageDto { + final String title; + final List items; + final List plans; + + SubscriptionPageDto({ + required this.title, + required this.items, + required this.plans, + }); + + factory SubscriptionPageDto.fromJson(Map json) => + _$SubscriptionPageDtoFromJson(json); + + Map toJson() => _$SubscriptionPageDtoToJson(this); +} + +@JsonSerializable() +@CopyWith() +class SubscriptionPlanDto implements MnemoCardsProductDto { + final String id; + + final String? titleLead; + final String? title; + + final String? subtitleCrossed; + final String? subtitle; + + final String price; + final String? pricePerMonth; + final String currency; + + final String? tip; + final String? tipColor; + + final String? deeplink; + + final List features; + + SubscriptionPlanDto({ + required this.id, + required this.titleLead, + required this.title, + required this.subtitle, + required this.subtitleCrossed, + required this.price, + required this.pricePerMonth, + required this.currency, + required this.tip, + required this.tipColor, + required this.features, + required this.deeplink, + }); + + factory SubscriptionPlanDto.fromJson(Map json) => + _$SubscriptionPlanDtoFromJson(json); + + Map toJson() => _$SubscriptionPlanDtoToJson(this); + + @override + MnemoCardsProductType get type => MnemoCardsProductType.subscription; + +// String? get googlePlaySubscriptionId => paymentSystem == PaymentSystem.google +// ? paymentId?.split('|').firstOrNull +// : null; +// +// String? get googlePlayPlanId => paymentSystem == PaymentSystem.google +// ? paymentId?.split('|').lastOrNull +// : null; +} diff --git a/mnemo_cards_common/lib/src/dtos/subscription/subscription_plan_dto.g.dart b/mnemo_cards_common/lib/src/dtos/subscription/subscription_plan_dto.g.dart new file mode 100644 index 0000000..edc36ba --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/subscription/subscription_plan_dto.g.dart @@ -0,0 +1,425 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'subscription_plan_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$SubscriptionDtoCWProxy { + SubscriptionDto page(SubscriptionPageDto? page); + + SubscriptionDto isActive(bool isActive); + + SubscriptionDto start(DateTime? start); + + SubscriptionDto finish(DateTime? finish); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SubscriptionDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// SubscriptionDto(...).copyWith(id: 12, name: "My name") + /// ```` + SubscriptionDto call({ + SubscriptionPageDto? page, + bool? isActive, + DateTime? start, + DateTime? finish, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfSubscriptionDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfSubscriptionDto.copyWith.fieldName(...)` +class _$SubscriptionDtoCWProxyImpl implements _$SubscriptionDtoCWProxy { + const _$SubscriptionDtoCWProxyImpl(this._value); + + final SubscriptionDto _value; + + @override + SubscriptionDto page(SubscriptionPageDto? page) => this(page: page); + + @override + SubscriptionDto isActive(bool isActive) => this(isActive: isActive); + + @override + SubscriptionDto start(DateTime? start) => this(start: start); + + @override + SubscriptionDto finish(DateTime? finish) => this(finish: finish); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SubscriptionDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// SubscriptionDto(...).copyWith(id: 12, name: "My name") + /// ```` + SubscriptionDto call({ + Object? page = const $CopyWithPlaceholder(), + Object? isActive = const $CopyWithPlaceholder(), + Object? start = const $CopyWithPlaceholder(), + Object? finish = const $CopyWithPlaceholder(), + }) { + return SubscriptionDto( + page: page == const $CopyWithPlaceholder() + ? _value.page + // ignore: cast_nullable_to_non_nullable + : page as SubscriptionPageDto?, + isActive: isActive == const $CopyWithPlaceholder() || isActive == null + ? _value.isActive + // ignore: cast_nullable_to_non_nullable + : isActive as bool, + start: start == const $CopyWithPlaceholder() + ? _value.start + // ignore: cast_nullable_to_non_nullable + : start as DateTime?, + finish: finish == const $CopyWithPlaceholder() + ? _value.finish + // ignore: cast_nullable_to_non_nullable + : finish as DateTime?, + ); + } +} + +extension $SubscriptionDtoCopyWith on SubscriptionDto { + /// Returns a callable class that can be used as follows: `instanceOfSubscriptionDto.copyWith(...)` or like so:`instanceOfSubscriptionDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$SubscriptionDtoCWProxy get copyWith => _$SubscriptionDtoCWProxyImpl(this); +} + +abstract class _$SubscriptionPageDtoCWProxy { + SubscriptionPageDto title(String title); + + SubscriptionPageDto items(List items); + + SubscriptionPageDto plans(List plans); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SubscriptionPageDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// SubscriptionPageDto(...).copyWith(id: 12, name: "My name") + /// ```` + SubscriptionPageDto call({ + String? title, + List? items, + List? plans, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfSubscriptionPageDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfSubscriptionPageDto.copyWith.fieldName(...)` +class _$SubscriptionPageDtoCWProxyImpl implements _$SubscriptionPageDtoCWProxy { + const _$SubscriptionPageDtoCWProxyImpl(this._value); + + final SubscriptionPageDto _value; + + @override + SubscriptionPageDto title(String title) => this(title: title); + + @override + SubscriptionPageDto items(List items) => this(items: items); + + @override + SubscriptionPageDto plans(List plans) => + this(plans: plans); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SubscriptionPageDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// SubscriptionPageDto(...).copyWith(id: 12, name: "My name") + /// ```` + SubscriptionPageDto call({ + Object? title = const $CopyWithPlaceholder(), + Object? items = const $CopyWithPlaceholder(), + Object? plans = const $CopyWithPlaceholder(), + }) { + return SubscriptionPageDto( + title: title == const $CopyWithPlaceholder() || title == null + ? _value.title + // ignore: cast_nullable_to_non_nullable + : title as String, + items: items == const $CopyWithPlaceholder() || items == null + ? _value.items + // ignore: cast_nullable_to_non_nullable + : items as List, + plans: plans == const $CopyWithPlaceholder() || plans == null + ? _value.plans + // ignore: cast_nullable_to_non_nullable + : plans as List, + ); + } +} + +extension $SubscriptionPageDtoCopyWith on SubscriptionPageDto { + /// Returns a callable class that can be used as follows: `instanceOfSubscriptionPageDto.copyWith(...)` or like so:`instanceOfSubscriptionPageDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$SubscriptionPageDtoCWProxy get copyWith => + _$SubscriptionPageDtoCWProxyImpl(this); +} + +abstract class _$SubscriptionPlanDtoCWProxy { + SubscriptionPlanDto id(String id); + + SubscriptionPlanDto titleLead(String? titleLead); + + SubscriptionPlanDto title(String? title); + + SubscriptionPlanDto subtitle(String? subtitle); + + SubscriptionPlanDto subtitleCrossed(String? subtitleCrossed); + + SubscriptionPlanDto price(String price); + + SubscriptionPlanDto pricePerMonth(String? pricePerMonth); + + SubscriptionPlanDto currency(String currency); + + SubscriptionPlanDto tip(String? tip); + + SubscriptionPlanDto tipColor(String? tipColor); + + SubscriptionPlanDto features(List features); + + SubscriptionPlanDto deeplink(String? deeplink); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SubscriptionPlanDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// SubscriptionPlanDto(...).copyWith(id: 12, name: "My name") + /// ```` + SubscriptionPlanDto call({ + String? id, + String? titleLead, + String? title, + String? subtitle, + String? subtitleCrossed, + String? price, + String? pricePerMonth, + String? currency, + String? tip, + String? tipColor, + List? features, + String? deeplink, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfSubscriptionPlanDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfSubscriptionPlanDto.copyWith.fieldName(...)` +class _$SubscriptionPlanDtoCWProxyImpl implements _$SubscriptionPlanDtoCWProxy { + const _$SubscriptionPlanDtoCWProxyImpl(this._value); + + final SubscriptionPlanDto _value; + + @override + SubscriptionPlanDto id(String id) => this(id: id); + + @override + SubscriptionPlanDto titleLead(String? titleLead) => + this(titleLead: titleLead); + + @override + SubscriptionPlanDto title(String? title) => this(title: title); + + @override + SubscriptionPlanDto subtitle(String? subtitle) => this(subtitle: subtitle); + + @override + SubscriptionPlanDto subtitleCrossed(String? subtitleCrossed) => + this(subtitleCrossed: subtitleCrossed); + + @override + SubscriptionPlanDto price(String price) => this(price: price); + + @override + SubscriptionPlanDto pricePerMonth(String? pricePerMonth) => + this(pricePerMonth: pricePerMonth); + + @override + SubscriptionPlanDto currency(String currency) => this(currency: currency); + + @override + SubscriptionPlanDto tip(String? tip) => this(tip: tip); + + @override + SubscriptionPlanDto tipColor(String? tipColor) => this(tipColor: tipColor); + + @override + SubscriptionPlanDto features(List features) => + this(features: features); + + @override + SubscriptionPlanDto deeplink(String? deeplink) => this(deeplink: deeplink); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SubscriptionPlanDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// SubscriptionPlanDto(...).copyWith(id: 12, name: "My name") + /// ```` + SubscriptionPlanDto call({ + Object? id = const $CopyWithPlaceholder(), + Object? titleLead = const $CopyWithPlaceholder(), + Object? title = const $CopyWithPlaceholder(), + Object? subtitle = const $CopyWithPlaceholder(), + Object? subtitleCrossed = const $CopyWithPlaceholder(), + Object? price = const $CopyWithPlaceholder(), + Object? pricePerMonth = const $CopyWithPlaceholder(), + Object? currency = const $CopyWithPlaceholder(), + Object? tip = const $CopyWithPlaceholder(), + Object? tipColor = const $CopyWithPlaceholder(), + Object? features = const $CopyWithPlaceholder(), + Object? deeplink = const $CopyWithPlaceholder(), + }) { + return SubscriptionPlanDto( + id: id == const $CopyWithPlaceholder() || id == null + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as String, + titleLead: titleLead == const $CopyWithPlaceholder() + ? _value.titleLead + // ignore: cast_nullable_to_non_nullable + : titleLead as String?, + title: title == const $CopyWithPlaceholder() + ? _value.title + // ignore: cast_nullable_to_non_nullable + : title as String?, + subtitle: subtitle == const $CopyWithPlaceholder() + ? _value.subtitle + // ignore: cast_nullable_to_non_nullable + : subtitle as String?, + subtitleCrossed: subtitleCrossed == const $CopyWithPlaceholder() + ? _value.subtitleCrossed + // ignore: cast_nullable_to_non_nullable + : subtitleCrossed as String?, + price: price == const $CopyWithPlaceholder() || price == null + ? _value.price + // ignore: cast_nullable_to_non_nullable + : price as String, + pricePerMonth: pricePerMonth == const $CopyWithPlaceholder() + ? _value.pricePerMonth + // ignore: cast_nullable_to_non_nullable + : pricePerMonth as String?, + currency: currency == const $CopyWithPlaceholder() || currency == null + ? _value.currency + // ignore: cast_nullable_to_non_nullable + : currency as String, + tip: tip == const $CopyWithPlaceholder() + ? _value.tip + // ignore: cast_nullable_to_non_nullable + : tip as String?, + tipColor: tipColor == const $CopyWithPlaceholder() + ? _value.tipColor + // ignore: cast_nullable_to_non_nullable + : tipColor as String?, + features: features == const $CopyWithPlaceholder() || features == null + ? _value.features + // ignore: cast_nullable_to_non_nullable + : features as List, + deeplink: deeplink == const $CopyWithPlaceholder() + ? _value.deeplink + // ignore: cast_nullable_to_non_nullable + : deeplink as String?, + ); + } +} + +extension $SubscriptionPlanDtoCopyWith on SubscriptionPlanDto { + /// Returns a callable class that can be used as follows: `instanceOfSubscriptionPlanDto.copyWith(...)` or like so:`instanceOfSubscriptionPlanDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$SubscriptionPlanDtoCWProxy get copyWith => + _$SubscriptionPlanDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SubscriptionDto _$SubscriptionDtoFromJson(Map json) => + SubscriptionDto( + page: json['page'] == null + ? null + : SubscriptionPageDto.fromJson(json['page'] as Map), + isActive: json['isActive'] as bool, + start: json['start'] == null + ? null + : DateTime.parse(json['start'] as String), + finish: json['finish'] == null + ? null + : DateTime.parse(json['finish'] as String), + ); + +Map _$SubscriptionDtoToJson(SubscriptionDto instance) => + { + 'page': instance.page, + 'isActive': instance.isActive, + 'start': instance.start?.toIso8601String(), + 'finish': instance.finish?.toIso8601String(), + }; + +SubscriptionPageDto _$SubscriptionPageDtoFromJson(Map json) => + SubscriptionPageDto( + title: json['title'] as String, + items: (json['items'] as List) + .map((e) => Item.fromJson(e as Map)) + .toList(), + plans: (json['plans'] as List) + .map((e) => SubscriptionPlanDto.fromJson(e as Map)) + .toList(), + ); + +Map _$SubscriptionPageDtoToJson( + SubscriptionPageDto instance) => + { + 'title': instance.title, + 'items': instance.items, + 'plans': instance.plans, + }; + +SubscriptionPlanDto _$SubscriptionPlanDtoFromJson(Map json) => + SubscriptionPlanDto( + id: json['id'] as String, + titleLead: json['titleLead'] as String?, + title: json['title'] as String?, + subtitle: json['subtitle'] as String?, + subtitleCrossed: json['subtitleCrossed'] as String?, + price: json['price'] as String, + pricePerMonth: json['pricePerMonth'] as String?, + currency: json['currency'] as String, + tip: json['tip'] as String?, + tipColor: json['tipColor'] as String?, + features: (json['features'] as List) + .map((e) => $enumDecode(_$SubscriptionFeatureEnumEnumMap, e)) + .toList(), + deeplink: json['deeplink'] as String?, + ); + +Map _$SubscriptionPlanDtoToJson( + SubscriptionPlanDto instance) => + { + 'id': instance.id, + 'titleLead': instance.titleLead, + 'title': instance.title, + 'subtitleCrossed': instance.subtitleCrossed, + 'subtitle': instance.subtitle, + 'price': instance.price, + 'pricePerMonth': instance.pricePerMonth, + 'currency': instance.currency, + 'tip': instance.tip, + 'tipColor': instance.tipColor, + 'deeplink': instance.deeplink, + 'features': instance.features + .map((e) => _$SubscriptionFeatureEnumEnumMap[e]!) + .toList(), + }; + +const _$SubscriptionFeatureEnumEnumMap = { + SubscriptionFeatureEnum.ads: 'ads', + SubscriptionFeatureEnum.packs: 'packs', + SubscriptionFeatureEnum.unknown: 'unknown', +}; diff --git a/mnemo_cards_common/lib/src/dtos/subscription/subscription_plan_ui_dto.dart b/mnemo_cards_common/lib/src/dtos/subscription/subscription_plan_ui_dto.dart new file mode 100644 index 0000000..6f34a76 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/subscription/subscription_plan_ui_dto.dart @@ -0,0 +1,36 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; + +part 'subscription_plan_ui_dto.g.dart'; + +@JsonSerializable() +@CopyWith() +class SubscriptionPlanUIDto { + final String? titleLead; + final String? title; + + final String? subtitleCrossed; + final String? subtitle; + + final String? pricePerMonth; + final String? currency; + + final String? tip; + final String? tipColor; + + const SubscriptionPlanUIDto({ + this.titleLead, + this.title, + this.subtitleCrossed, + this.subtitle, + this.pricePerMonth, + this.currency, + this.tip, + this.tipColor, + }); + + factory SubscriptionPlanUIDto.fromJson(Map json) => + _$SubscriptionPlanUIDtoFromJson(json); + + Map toJson() => _$SubscriptionPlanUIDtoToJson(this); +} \ No newline at end of file diff --git a/mnemo_cards_common/lib/src/dtos/subscription/subscription_plan_ui_dto.g.dart b/mnemo_cards_common/lib/src/dtos/subscription/subscription_plan_ui_dto.g.dart new file mode 100644 index 0000000..7a6771d --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/subscription/subscription_plan_ui_dto.g.dart @@ -0,0 +1,168 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'subscription_plan_ui_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$SubscriptionPlanUIDtoCWProxy { + SubscriptionPlanUIDto titleLead(String? titleLead); + + SubscriptionPlanUIDto title(String? title); + + SubscriptionPlanUIDto subtitleCrossed(String? subtitleCrossed); + + SubscriptionPlanUIDto subtitle(String? subtitle); + + SubscriptionPlanUIDto pricePerMonth(String? pricePerMonth); + + SubscriptionPlanUIDto currency(String? currency); + + SubscriptionPlanUIDto tip(String? tip); + + SubscriptionPlanUIDto tipColor(String? tipColor); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SubscriptionPlanUIDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// SubscriptionPlanUIDto(...).copyWith(id: 12, name: "My name") + /// ```` + SubscriptionPlanUIDto call({ + String? titleLead, + String? title, + String? subtitleCrossed, + String? subtitle, + String? pricePerMonth, + String? currency, + String? tip, + String? tipColor, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfSubscriptionPlanUIDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfSubscriptionPlanUIDto.copyWith.fieldName(...)` +class _$SubscriptionPlanUIDtoCWProxyImpl + implements _$SubscriptionPlanUIDtoCWProxy { + const _$SubscriptionPlanUIDtoCWProxyImpl(this._value); + + final SubscriptionPlanUIDto _value; + + @override + SubscriptionPlanUIDto titleLead(String? titleLead) => + this(titleLead: titleLead); + + @override + SubscriptionPlanUIDto title(String? title) => this(title: title); + + @override + SubscriptionPlanUIDto subtitleCrossed(String? subtitleCrossed) => + this(subtitleCrossed: subtitleCrossed); + + @override + SubscriptionPlanUIDto subtitle(String? subtitle) => this(subtitle: subtitle); + + @override + SubscriptionPlanUIDto pricePerMonth(String? pricePerMonth) => + this(pricePerMonth: pricePerMonth); + + @override + SubscriptionPlanUIDto currency(String? currency) => this(currency: currency); + + @override + SubscriptionPlanUIDto tip(String? tip) => this(tip: tip); + + @override + SubscriptionPlanUIDto tipColor(String? tipColor) => this(tipColor: tipColor); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SubscriptionPlanUIDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// SubscriptionPlanUIDto(...).copyWith(id: 12, name: "My name") + /// ```` + SubscriptionPlanUIDto call({ + Object? titleLead = const $CopyWithPlaceholder(), + Object? title = const $CopyWithPlaceholder(), + Object? subtitleCrossed = const $CopyWithPlaceholder(), + Object? subtitle = const $CopyWithPlaceholder(), + Object? pricePerMonth = const $CopyWithPlaceholder(), + Object? currency = const $CopyWithPlaceholder(), + Object? tip = const $CopyWithPlaceholder(), + Object? tipColor = const $CopyWithPlaceholder(), + }) { + return SubscriptionPlanUIDto( + titleLead: titleLead == const $CopyWithPlaceholder() + ? _value.titleLead + // ignore: cast_nullable_to_non_nullable + : titleLead as String?, + title: title == const $CopyWithPlaceholder() + ? _value.title + // ignore: cast_nullable_to_non_nullable + : title as String?, + subtitleCrossed: subtitleCrossed == const $CopyWithPlaceholder() + ? _value.subtitleCrossed + // ignore: cast_nullable_to_non_nullable + : subtitleCrossed as String?, + subtitle: subtitle == const $CopyWithPlaceholder() + ? _value.subtitle + // ignore: cast_nullable_to_non_nullable + : subtitle as String?, + pricePerMonth: pricePerMonth == const $CopyWithPlaceholder() + ? _value.pricePerMonth + // ignore: cast_nullable_to_non_nullable + : pricePerMonth as String?, + currency: currency == const $CopyWithPlaceholder() + ? _value.currency + // ignore: cast_nullable_to_non_nullable + : currency as String?, + tip: tip == const $CopyWithPlaceholder() + ? _value.tip + // ignore: cast_nullable_to_non_nullable + : tip as String?, + tipColor: tipColor == const $CopyWithPlaceholder() + ? _value.tipColor + // ignore: cast_nullable_to_non_nullable + : tipColor as String?, + ); + } +} + +extension $SubscriptionPlanUIDtoCopyWith on SubscriptionPlanUIDto { + /// Returns a callable class that can be used as follows: `instanceOfSubscriptionPlanUIDto.copyWith(...)` or like so:`instanceOfSubscriptionPlanUIDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$SubscriptionPlanUIDtoCWProxy get copyWith => + _$SubscriptionPlanUIDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SubscriptionPlanUIDto _$SubscriptionPlanUIDtoFromJson( + Map json) => + SubscriptionPlanUIDto( + titleLead: json['titleLead'] as String?, + title: json['title'] as String?, + subtitleCrossed: json['subtitleCrossed'] as String?, + subtitle: json['subtitle'] as String?, + pricePerMonth: json['pricePerMonth'] as String?, + currency: json['currency'] as String?, + tip: json['tip'] as String?, + tipColor: json['tipColor'] as String?, + ); + +Map _$SubscriptionPlanUIDtoToJson( + SubscriptionPlanUIDto instance) => + { + 'titleLead': instance.titleLead, + 'title': instance.title, + 'subtitleCrossed': instance.subtitleCrossed, + 'subtitle': instance.subtitle, + 'pricePerMonth': instance.pricePerMonth, + 'currency': instance.currency, + 'tip': instance.tip, + 'tipColor': instance.tipColor, + }; diff --git a/mnemo_cards_common/lib/src/dtos/user/achievement_dto.dart b/mnemo_cards_common/lib/src/dtos/user/achievement_dto.dart new file mode 100644 index 0000000..7de62e0 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/achievement_dto.dart @@ -0,0 +1,366 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; + +part 'achievement_dto.g.dart'; + +/// Achievement types available in the system +enum AchievementType { + /// First steps achievements + firstWordLearned, + firstTestCompleted, + firstPackCompleted, + + /// Streak achievements + streak3Days, + streak7Days, + streak30Days, + streak100Days, + + /// Words mastery achievements + words10Learned, + words50Learned, + words100Learned, + words500Learned, + words1000Learned, + + /// Test performance achievements + perfectTestScore, + speedLearner, // Complete pack in less than 1 day + dedicatedLearner, // Study time milestones + + /// Time-based achievements + nightOwl, // Study after 10 PM + earlyBird, // Study before 6 AM + + /// Special achievements + consistentLearner, // Study every day for a month + languageMaster, // Complete multiple packs +} + +/// Achievement data structure +@JsonSerializable() +@CopyWith() +class AchievementDto { + /// Unique achievement identifier + final String id; + + /// Achievement title (localized) + final String title; + + /// Achievement description (localized) + final String description; + + /// URL to achievement icon/badge image + final String? iconUrl; + + /// When this achievement was unlocked (null if locked) + final DateTime? unlockedAt; + + /// Achievement type for categorization + final AchievementType type; + + /// Progress towards unlocking (0.0 to 1.0 for locked achievements) + final double progress; + + const AchievementDto({ + required this.id, + required this.title, + required this.description, + this.iconUrl, + this.unlockedAt, + required this.type, + this.progress = 0.0, + }); + + factory AchievementDto.fromJson(Map json) => + _$AchievementDtoFromJson(json); + + Map toJson() => _$AchievementDtoToJson(this); + + /// Check if achievement is unlocked + bool get isUnlocked => unlockedAt != null; + + /// Check if achievement is locked + bool get isLocked => unlockedAt == null; + + /// Create achievement with current unlock time + AchievementDto unlock() => AchievementDto( + id: id, + title: title, + description: description, + iconUrl: iconUrl, + unlockedAt: DateTime.now(), + type: type, + progress: 1.0, + ); + + /// Update progress + AchievementDto updateProgress(double newProgress) => AchievementDto( + id: id, + title: title, + description: description, + iconUrl: iconUrl, + unlockedAt: unlockedAt, + type: type, + progress: newProgress.clamp(0.0, 1.0), + ); + + /// Get achievement category + String get category { + switch (type) { + case AchievementType.firstWordLearned: + case AchievementType.firstTestCompleted: + case AchievementType.firstPackCompleted: + return 'first_steps'; + + case AchievementType.streak3Days: + case AchievementType.streak7Days: + case AchievementType.streak30Days: + case AchievementType.streak100Days: + return 'streaks'; + + case AchievementType.words10Learned: + case AchievementType.words50Learned: + case AchievementType.words100Learned: + case AchievementType.words500Learned: + case AchievementType.words1000Learned: + return 'words_mastery'; + + case AchievementType.perfectTestScore: + case AchievementType.speedLearner: + return 'performance'; + + case AchievementType.dedicatedLearner: + return 'dedication'; + + case AchievementType.nightOwl: + case AchievementType.earlyBird: + return 'time_based'; + + case AchievementType.consistentLearner: + case AchievementType.languageMaster: + return 'special'; + } + } + + /// Get sort order within category + int get sortOrder { + switch (type) { + case AchievementType.firstWordLearned: + return 1; + case AchievementType.firstTestCompleted: + return 2; + case AchievementType.firstPackCompleted: + return 3; + + case AchievementType.streak3Days: + return 1; + case AchievementType.streak7Days: + return 2; + case AchievementType.streak30Days: + return 3; + case AchievementType.streak100Days: + return 4; + + case AchievementType.words10Learned: + return 1; + case AchievementType.words50Learned: + return 2; + case AchievementType.words100Learned: + return 3; + case AchievementType.words500Learned: + return 4; + case AchievementType.words1000Learned: + return 5; + + case AchievementType.perfectTestScore: + return 1; + case AchievementType.speedLearner: + return 2; + case AchievementType.dedicatedLearner: + return 3; + + case AchievementType.earlyBird: + return 1; + case AchievementType.nightOwl: + return 2; + + case AchievementType.consistentLearner: + return 1; + case AchievementType.languageMaster: + return 2; + } + } + + @override + bool operator ==(Object other) => + identical(this, other) || + other is AchievementDto && + runtimeType == other.runtimeType && + id == other.id && + title == other.title && + description == other.description && + iconUrl == other.iconUrl && + unlockedAt == other.unlockedAt && + type == other.type && + progress == other.progress; + + @override + int get hashCode => + id.hashCode ^ + title.hashCode ^ + description.hashCode ^ + iconUrl.hashCode ^ + unlockedAt.hashCode ^ + type.hashCode ^ + progress.hashCode; + + @override + String toString() => + 'AchievementDto(id: $id, title: $title, unlocked: $isUnlocked, progress: $progress)'; +} + +/// Predefined achievements configuration +class AchievementDefinitions { + static const allAchievements = [ + AchievementDto( + id: 'first_word', + title: 'First Word', + description: 'Learn your first word', + type: AchievementType.firstWordLearned, + ), + AchievementDto( + id: 'first_test', + title: 'First Test', + description: 'Complete your first test', + type: AchievementType.firstTestCompleted, + ), + AchievementDto( + id: 'first_pack', + title: 'First Pack', + description: 'Complete your first pack', + type: AchievementType.firstPackCompleted, + ), + + AchievementDto( + id: 'streak_3', + title: '3-Day Streak', + description: 'Study for 3 consecutive days', + type: AchievementType.streak3Days, + ), + AchievementDto( + id: 'streak_7', + title: 'Week Warrior', + description: 'Study for 7 consecutive days', + type: AchievementType.streak7Days, + ), + AchievementDto( + id: 'streak_30', + title: 'Monthly Master', + description: 'Study for 30 consecutive days', + type: AchievementType.streak30Days, + ), + AchievementDto( + id: 'streak_100', + title: 'Century Champion', + description: 'Study for 100 consecutive days', + type: AchievementType.streak100Days, + ), + + AchievementDto( + id: 'words_10', + title: 'Word Explorer', + description: 'Learn 10 words', + type: AchievementType.words10Learned, + ), + AchievementDto( + id: 'words_50', + title: 'Vocabulary Builder', + description: 'Learn 50 words', + type: AchievementType.words50Learned, + ), + AchievementDto( + id: 'words_100', + title: 'Language Learner', + description: 'Learn 100 words', + type: AchievementType.words100Learned, + ), + AchievementDto( + id: 'words_500', + title: 'Word Master', + description: 'Learn 500 words', + type: AchievementType.words500Learned, + ), + AchievementDto( + id: 'words_1000', + title: 'Vocabulary Expert', + description: 'Learn 1000 words', + type: AchievementType.words1000Learned, + ), + + AchievementDto( + id: 'perfect_test', + title: 'Perfect Score', + description: 'Get 100% on a test', + type: AchievementType.perfectTestScore, + ), + AchievementDto( + id: 'speed_learner', + title: 'Speed Learner', + description: 'Complete a pack in less than 24 hours', + type: AchievementType.speedLearner, + ), + AchievementDto( + id: 'dedicated_learner', + title: 'Dedicated Learner', + description: 'Study for 100 hours total', + type: AchievementType.dedicatedLearner, + ), + + AchievementDto( + id: 'early_bird', + title: 'Early Bird', + description: 'Study before 6 AM', + type: AchievementType.earlyBird, + ), + AchievementDto( + id: 'night_owl', + title: 'Night Owl', + description: 'Study after 10 PM', + type: AchievementType.nightOwl, + ), + + AchievementDto( + id: 'consistent_learner', + title: 'Consistent Learner', + description: 'Study every day for 30 days', + type: AchievementType.consistentLearner, + ), + AchievementDto( + id: 'language_master', + title: 'Language Master', + description: 'Complete 10 packs', + type: AchievementType.languageMaster, + ), + ]; + + /// Get achievement definition by ID + static AchievementDto? getById(String id) { + return allAchievements.where((achievement) => achievement.id == id).firstOrNull; + } + + /// Get achievements by category + static List getByCategory(String category) { + return allAchievements.where((achievement) => achievement.category == category).toList(); + } +} + +extension on Iterable { + AchievementDto? get firstOrNull { + try { + return first; + } catch (_) { + return null; + } + } +} diff --git a/mnemo_cards_common/lib/src/dtos/user/achievement_dto.g.dart b/mnemo_cards_common/lib/src/dtos/user/achievement_dto.g.dart new file mode 100644 index 0000000..9219130 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/achievement_dto.g.dart @@ -0,0 +1,53 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'achievement_dto.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +AchievementDto _$AchievementDtoFromJson(Map json) => + AchievementDto( + id: json['id'] as String, + title: json['title'] as String, + description: json['description'] as String, + iconUrl: json['iconUrl'] as String?, + unlockedAt: json['unlockedAt'] == null + ? null + : DateTime.parse(json['unlockedAt'] as String), + type: $enumDecode(_$AchievementTypeEnumMap, json['type']), + progress: (json['progress'] as num?)?.toDouble() ?? 0.0, + ); + +Map _$AchievementDtoToJson(AchievementDto instance) => + { + 'id': instance.id, + 'title': instance.title, + 'description': instance.description, + 'iconUrl': instance.iconUrl, + 'unlockedAt': instance.unlockedAt?.toIso8601String(), + 'type': _$AchievementTypeEnumMap[instance.type], + 'progress': instance.progress, + }; + +const _$AchievementTypeEnumMap = { + AchievementType.firstWordLearned: 'firstWordLearned', + AchievementType.firstTestCompleted: 'firstTestCompleted', + AchievementType.firstPackCompleted: 'firstPackCompleted', + AchievementType.streak3Days: 'streak3Days', + AchievementType.streak7Days: 'streak7Days', + AchievementType.streak30Days: 'streak30Days', + AchievementType.streak100Days: 'streak100Days', + AchievementType.words10Learned: 'words10Learned', + AchievementType.words50Learned: 'words50Learned', + AchievementType.words100Learned: 'words100Learned', + AchievementType.words500Learned: 'words500Learned', + AchievementType.words1000Learned: 'words1000Learned', + AchievementType.perfectTestScore: 'perfectTestScore', + AchievementType.speedLearner: 'speedLearner', + AchievementType.dedicatedLearner: 'dedicatedLearner', + AchievementType.nightOwl: 'nightOwl', + AchievementType.earlyBird: 'earlyBird', + AchievementType.consistentLearner: 'consistentLearner', + AchievementType.languageMaster: 'languageMaster', +}; diff --git a/mnemo_cards_common/lib/src/dtos/user/data/all_tests_statistics_dto.dart b/mnemo_cards_common/lib/src/dtos/user/data/all_tests_statistics_dto.dart new file mode 100644 index 0000000..792837b --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/data/all_tests_statistics_dto.dart @@ -0,0 +1,48 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:mnemo_cards_common/mnemo_cards_common.dart'; + +part 'all_tests_statistics_dto.g.dart'; + +@JsonSerializable() +@CopyWith() +class AllTestsStatisticsDto { + final Map tests; + final String? lastSessionToken; + + AllTestsStatisticsDto({ + required this.tests, + required this.lastSessionToken, + }); + + AllTestsStatisticsDto.empty() + : tests = const {}, + lastSessionToken = null; + + factory AllTestsStatisticsDto.fromJson(Map json) => + _$AllTestsStatisticsDtoFromJson(json); + + Map toJson() => _$AllTestsStatisticsDtoToJson(this); + + AllTestsStatisticsDto add(TestStatisticsDto testStat) { + return copyWith( + tests: Map.from(tests)..[testStat.testId] = testStat, + lastSessionToken: testStat.sessionToken, + ); + } + + // AllTestsStatisticsDto merge( + // AllTestsStatisticsDto other, + // String? sessionKey, + // ) { + // final updatedTests = Map.of(tests); + // for (final entry in other.tests.entries) { + // updatedTests[entry.key] = + // tests[entry.key]?.merge(entry.value) ?? entry.value; + // } + // return copyWith( + // tests: updatedTests, + // lastSessionToken: sessionKey, + // ); + // } +} diff --git a/mnemo_cards_common/lib/src/dtos/user/data/all_tests_statistics_dto.g.dart b/mnemo_cards_common/lib/src/dtos/user/data/all_tests_statistics_dto.g.dart new file mode 100644 index 0000000..1af609c --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/data/all_tests_statistics_dto.g.dart @@ -0,0 +1,92 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'all_tests_statistics_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$AllTestsStatisticsDtoCWProxy { + AllTestsStatisticsDto tests(Map tests); + + AllTestsStatisticsDto lastSessionToken(String? lastSessionToken); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `AllTestsStatisticsDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// AllTestsStatisticsDto(...).copyWith(id: 12, name: "My name") + /// ```` + AllTestsStatisticsDto call({ + Map? tests, + String? lastSessionToken, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfAllTestsStatisticsDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfAllTestsStatisticsDto.copyWith.fieldName(...)` +class _$AllTestsStatisticsDtoCWProxyImpl + implements _$AllTestsStatisticsDtoCWProxy { + const _$AllTestsStatisticsDtoCWProxyImpl(this._value); + + final AllTestsStatisticsDto _value; + + @override + AllTestsStatisticsDto tests(Map tests) => + this(tests: tests); + + @override + AllTestsStatisticsDto lastSessionToken(String? lastSessionToken) => + this(lastSessionToken: lastSessionToken); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `AllTestsStatisticsDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// AllTestsStatisticsDto(...).copyWith(id: 12, name: "My name") + /// ```` + AllTestsStatisticsDto call({ + Object? tests = const $CopyWithPlaceholder(), + Object? lastSessionToken = const $CopyWithPlaceholder(), + }) { + return AllTestsStatisticsDto( + tests: tests == const $CopyWithPlaceholder() || tests == null + ? _value.tests + // ignore: cast_nullable_to_non_nullable + : tests as Map, + lastSessionToken: lastSessionToken == const $CopyWithPlaceholder() + ? _value.lastSessionToken + // ignore: cast_nullable_to_non_nullable + : lastSessionToken as String?, + ); + } +} + +extension $AllTestsStatisticsDtoCopyWith on AllTestsStatisticsDto { + /// Returns a callable class that can be used as follows: `instanceOfAllTestsStatisticsDto.copyWith(...)` or like so:`instanceOfAllTestsStatisticsDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$AllTestsStatisticsDtoCWProxy get copyWith => + _$AllTestsStatisticsDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +AllTestsStatisticsDto _$AllTestsStatisticsDtoFromJson( + Map json) => + AllTestsStatisticsDto( + tests: (json['tests'] as Map).map( + (k, e) => MapEntry(int.parse(k), + TestStatisticsDto.fromJson(e as Map)), + ), + lastSessionToken: json['lastSessionToken'] as String?, + ); + +Map _$AllTestsStatisticsDtoToJson( + AllTestsStatisticsDto instance) => + { + 'tests': instance.tests.map((k, e) => MapEntry(k.toString(), e)), + 'lastSessionToken': instance.lastSessionToken, + }; diff --git a/mnemo_cards_common/lib/src/dtos/user/data/all_words_statistics_dto.dart b/mnemo_cards_common/lib/src/dtos/user/data/all_words_statistics_dto.dart new file mode 100644 index 0000000..d94e7f4 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/data/all_words_statistics_dto.dart @@ -0,0 +1,59 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:mnemo_cards_common/mnemo_cards_common.dart'; +import 'package:mnemo_cards_common/src/utils/word_statistics.dart'; +import 'package:collection/collection.dart'; + +part 'all_words_statistics_dto.g.dart'; + +@JsonSerializable() +@CopyWith() +class AllWordsStatisticsDto { + // final Map words; + final List words; + + AllWordsStatisticsDto({ + this.words = const [], + }); + + double get correct => words.correct; + + double get incorrect => words.incorrect; + + double get skipped => words.skipped; + + double get total => words.fold( + 0.0, + (s, v) => s + v.skipped + v.correct + v.incorrect, + ); + + AllWordsStatisticsDto.empty() : words = const []; + + factory AllWordsStatisticsDto.fromJson(Map json) => + _$AllWordsStatisticsDtoFromJson(json); + + Map toJson() => _$AllWordsStatisticsDtoToJson(this); + + @override + int get hashCode => words.hashCode; + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is AllWordsStatisticsDto && + const ListEquality().equals(other.words, words); + } + +// AllWordsStatisticsDto merge(AllWordsStatisticsDto? other) { +// if (other == null) { +// return copyWith(); +// } +// final updatedWords = Map.of(words); +// for (final entry in other.words.entries) { +// updatedWords[entry.key] = +// words[entry.key]?.merge(entry.value) ?? entry.value; +// } +// return copyWith.words(updatedWords); +// } +} diff --git a/mnemo_cards_common/lib/src/dtos/user/data/all_words_statistics_dto.g.dart b/mnemo_cards_common/lib/src/dtos/user/data/all_words_statistics_dto.g.dart new file mode 100644 index 0000000..bb28e45 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/data/all_words_statistics_dto.g.dart @@ -0,0 +1,79 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'all_words_statistics_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$AllWordsStatisticsDtoCWProxy { + AllWordsStatisticsDto words(List words); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `AllWordsStatisticsDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// AllWordsStatisticsDto(...).copyWith(id: 12, name: "My name") + /// ```` + AllWordsStatisticsDto call({ + List? words, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfAllWordsStatisticsDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfAllWordsStatisticsDto.copyWith.fieldName(...)` +class _$AllWordsStatisticsDtoCWProxyImpl + implements _$AllWordsStatisticsDtoCWProxy { + const _$AllWordsStatisticsDtoCWProxyImpl(this._value); + + final AllWordsStatisticsDto _value; + + @override + AllWordsStatisticsDto words(List words) => + this(words: words); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `AllWordsStatisticsDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// AllWordsStatisticsDto(...).copyWith(id: 12, name: "My name") + /// ```` + AllWordsStatisticsDto call({ + Object? words = const $CopyWithPlaceholder(), + }) { + return AllWordsStatisticsDto( + words: words == const $CopyWithPlaceholder() || words == null + ? _value.words + // ignore: cast_nullable_to_non_nullable + : words as List, + ); + } +} + +extension $AllWordsStatisticsDtoCopyWith on AllWordsStatisticsDto { + /// Returns a callable class that can be used as follows: `instanceOfAllWordsStatisticsDto.copyWith(...)` or like so:`instanceOfAllWordsStatisticsDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$AllWordsStatisticsDtoCWProxy get copyWith => + _$AllWordsStatisticsDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +AllWordsStatisticsDto _$AllWordsStatisticsDtoFromJson( + Map json) => + AllWordsStatisticsDto( + words: (json['words'] as List?) + ?.map( + (e) => WordStatisticsDto.fromJson(e as Map)) + .toList() ?? + const [], + ); + +Map _$AllWordsStatisticsDtoToJson( + AllWordsStatisticsDto instance) => + { + 'words': instance.words, + }; diff --git a/mnemo_cards_common/lib/src/dtos/user/data/detailed_word_statistics_dto.dart b/mnemo_cards_common/lib/src/dtos/user/data/detailed_word_statistics_dto.dart new file mode 100644 index 0000000..819de94 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/data/detailed_word_statistics_dto.dart @@ -0,0 +1,339 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:collection/collection.dart'; +import 'package:mnemo_cards_common/mnemo_cards_common.dart'; + +part 'detailed_word_statistics_dto.g.dart'; + +/// Extended word statistics with additional tracking data +@JsonSerializable() +@CopyWith() +class DetailedWordStatisticsDto extends WordStatisticsDto { + /// When this word was last reviewed + final DateTime? lastReviewed; + + /// When this word was first learned + final DateTime? firstLearned; + + /// Recent attempts (last 10, for trend analysis) + final List recentAttempts; + + /// Difficulty score (0.0 = easy, 1.0 = hard, based on incorrect/correct ratio) + final double difficultyScore; + + /// Whether this word needs review (based on performance and time since last review) + final bool needsReview; + + /// Which pack this word belongs to + final String? packId; + + DetailedWordStatisticsDto({ + required String word, + double correct = 0, + double incorrect = 0, + double skipped = 0, + Set questionTypes = const {}, + this.lastReviewed, + this.firstLearned, + this.recentAttempts = const [], + this.difficultyScore = 0.0, + this.needsReview = false, + this.packId, + }) : super( + word: word, + correct: correct, + incorrect: incorrect, + skipped: skipped, + questionTypes: questionTypes, + ); + + factory DetailedWordStatisticsDto.fromJson(Map json) => + _$DetailedWordStatisticsDtoFromJson(json); + + @override + Map toJson() => _$DetailedWordStatisticsDtoToJson(this); + + /// Create from base WordStatisticsDto + factory DetailedWordStatisticsDto.fromWordStatisticsDto( + WordStatisticsDto base, { + DateTime? lastReviewed, + DateTime? firstLearned, + List? recentAttempts, + double? difficultyScore, + bool? needsReview, + String? packId, + }) => + DetailedWordStatisticsDto( + word: base.word, + correct: base.correct, + incorrect: base.incorrect, + skipped: base.skipped, + questionTypes: base.questionTypes, + lastReviewed: lastReviewed, + firstLearned: firstLearned, + recentAttempts: recentAttempts ?? [], + difficultyScore: difficultyScore ?? _calculateDifficultyScore(base), + needsReview: needsReview ?? false, + packId: packId, + ); + + /// Calculate difficulty score from basic statistics + static double _calculateDifficultyScore(WordStatisticsDto stats) { + final total = stats.total; + if (total == 0) return 0.0; + + // Difficulty based on incorrect ratio + final incorrectRatio = stats.incorrect / total; + + // Also consider if word has many skips + final skipRatio = stats.skipped / total; + + // Weighted formula + return (incorrectRatio * 0.7 + skipRatio * 0.3).clamp(0.0, 1.0); + } + + /// Update statistics with new attempt + DetailedWordStatisticsDto addAttempt({ + required bool wasCorrect, + required TestQuestionType questionType, + DateTime? timestamp, + String? packId, + }) { + final now = timestamp ?? DateTime.now(); + + final newCorrect = wasCorrect ? correct + 1 : correct; + final newIncorrect = wasCorrect ? incorrect : incorrect + 1; + + final newQuestionTypes = {...questionTypes, questionType}; + + final newRecentAttempts = [ + WordAttemptDto( + timestamp: now, + wasCorrect: wasCorrect, + questionType: questionType, + ), + ...recentAttempts.take(9), // Keep only last 10 + ]; + + final newDifficultyScore = _calculateDifficultyScore( + WordStatisticsDto( + word: word, + correct: newCorrect, + incorrect: newIncorrect, + skipped: skipped, + questionTypes: newQuestionTypes, + ), + ); + + // Word needs review if: + // - Difficulty score > 0.5, OR + // - Last reviewed more than 7 days ago and has errors, OR + // - Never reviewed but has attempts + final daysSinceLastReview = lastReviewed != null + ? now.difference(lastReviewed!).inDays + : null; + + final needsReviewNow = + newDifficultyScore > 0.5 || + (daysSinceLastReview != null && + daysSinceLastReview > 7 && + (newIncorrect > 0 || newRecentAttempts.where((a) => !a.wasCorrect).length > 2)); + + return DetailedWordStatisticsDto( + word: word, + correct: newCorrect, + incorrect: newIncorrect, + skipped: skipped, + questionTypes: newQuestionTypes, + lastReviewed: now, + firstLearned: firstLearned ?? now, + recentAttempts: newRecentAttempts, + difficultyScore: newDifficultyScore, + needsReview: needsReviewNow, + packId: packId ?? this.packId, + ); + } + + /// Mark word as skipped + DetailedWordStatisticsDto addSkip({ + required TestQuestionType questionType, + DateTime? timestamp, + String? packId, + }) { + final now = timestamp ?? DateTime.now(); + + final newQuestionTypes = {...questionTypes, questionType}; + + final newRecentAttempts = [ + WordAttemptDto( + timestamp: now, + wasCorrect: false, + questionType: questionType, + wasSkipped: true, + ), + ...recentAttempts.take(9), + ]; + + final newDifficultyScore = _calculateDifficultyScore( + WordStatisticsDto( + word: word, + correct: correct, + incorrect: incorrect, + skipped: skipped + 1, + questionTypes: newQuestionTypes, + ), + ); + + return DetailedWordStatisticsDto( + word: word, + correct: correct, + incorrect: incorrect, + skipped: skipped + 1, + questionTypes: newQuestionTypes, + lastReviewed: now, + firstLearned: firstLearned ?? now, + recentAttempts: newRecentAttempts, + difficultyScore: newDifficultyScore, + needsReview: needsReview, + packId: packId ?? this.packId, + ); + } + + /// Get recent performance trend (last 5 attempts) + PerformanceTrend get performanceTrend { + if (recentAttempts.length < 3) return PerformanceTrend.insufficientData; + + final last5 = recentAttempts.take(5); + final correctCount = last5.where((a) => a.wasCorrect).length; + final accuracy = correctCount / last5.length; + + if (accuracy >= 0.8) return PerformanceTrend.improving; + if (accuracy <= 0.4) return PerformanceTrend.declining; + return PerformanceTrend.stable; + } + + /// Check if word should be prioritized for review + bool get shouldPrioritize { + return needsReview || + difficultyScore > 0.6 || + (performanceTrend == PerformanceTrend.declining); + } + + /// Get days since last review + int? get daysSinceLastReview { + if (lastReviewed == null) return null; + return DateTime.now().difference(lastReviewed!).inDays; + } + + /// Get total review count + int get reviewCount => recentAttempts.length; + + /// Get accuracy from recent attempts + double get recentAccuracy { + if (recentAttempts.isEmpty) return 0.0; + final correctCount = recentAttempts.where((a) => a.wasCorrect).length; + return correctCount / recentAttempts.length; + } + + @override + bool operator ==(Object other) => + identical(this, other) || + other is DetailedWordStatisticsDto && + runtimeType == other.runtimeType && + word == other.word && + correct == other.correct && + incorrect == other.incorrect && + skipped == other.skipped && + const SetEquality().equals(questionTypes, other.questionTypes) && + lastReviewed == other.lastReviewed && + firstLearned == other.firstLearned && + _listEquals(recentAttempts, other.recentAttempts) && + difficultyScore == other.difficultyScore && + needsReview == other.needsReview && + packId == other.packId; + + @override + int get hashCode => + word.hashCode ^ + correct.hashCode ^ + incorrect.hashCode ^ + skipped.hashCode ^ + questionTypes.hashCode ^ + lastReviewed.hashCode ^ + firstLearned.hashCode ^ + recentAttempts.hashCode ^ + difficultyScore.hashCode ^ + needsReview.hashCode ^ + packId.hashCode; + + @override + String toString() => + 'DetailedWordStatisticsDto(word: $word, accuracy: ${(correct / total * 100).toStringAsFixed(1)}%, difficulty: ${difficultyScore.toStringAsFixed(2)}, needsReview: $needsReview)'; +} + +/// Individual word attempt data +@JsonSerializable() +@CopyWith() +class WordAttemptDto { + /// When the attempt happened + final DateTime timestamp; + + /// Whether the answer was correct + final bool wasCorrect; + + /// Type of question asked + final TestQuestionType questionType; + + /// Whether the question was skipped + final bool wasSkipped; + + const WordAttemptDto({ + required this.timestamp, + required this.wasCorrect, + required this.questionType, + this.wasSkipped = false, + }); + + factory WordAttemptDto.fromJson(Map json) => + _$WordAttemptDtoFromJson(json); + + Map toJson() => _$WordAttemptDtoToJson(this); + + @override + bool operator ==(Object other) => + identical(this, other) || + other is WordAttemptDto && + runtimeType == other.runtimeType && + timestamp == other.timestamp && + wasCorrect == other.wasCorrect && + questionType == other.questionType && + wasSkipped == other.wasSkipped; + + @override + int get hashCode => + timestamp.hashCode ^ + wasCorrect.hashCode ^ + questionType.hashCode ^ + wasSkipped.hashCode; + + @override + String toString() => + 'WordAttemptDto(timestamp: $timestamp, correct: $wasCorrect, type: $questionType, skipped: $wasSkipped)'; +} + +/// Performance trend analysis +enum PerformanceTrend { + improving, + stable, + declining, + insufficientData, +} + + +bool _listEquals(List a, List b) { + if (a.length != b.length) return false; + for (int i = 0; i < a.length; i++) { + if (a[i] != b[i]) return false; + } + return true; +} diff --git a/mnemo_cards_common/lib/src/dtos/user/data/detailed_word_statistics_dto.g.dart b/mnemo_cards_common/lib/src/dtos/user/data/detailed_word_statistics_dto.g.dart new file mode 100644 index 0000000..ab34bb4 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/data/detailed_word_statistics_dto.g.dart @@ -0,0 +1,75 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'detailed_word_statistics_dto.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +DetailedWordStatisticsDto _$DetailedWordStatisticsDtoFromJson( + Map json) => + DetailedWordStatisticsDto( + word: json['word'] as String, + correct: (json['correct'] as num).toDouble(), + incorrect: (json['incorrect'] as num).toDouble(), + skipped: (json['skipped'] as num).toDouble(), + questionTypes: (json['questionTypes'] as List?) + ?.map((e) => $enumDecode(_$TestQuestionTypeEnumMap, e)) + .toSet() ?? + {}, + lastReviewed: json['lastReviewed'] == null + ? null + : DateTime.parse(json['lastReviewed'] as String), + firstLearned: json['firstLearned'] == null + ? null + : DateTime.parse(json['firstLearned'] as String), + recentAttempts: (json['recentAttempts'] as List?) + ?.map((e) => WordAttemptDto.fromJson(e as Map)) + .toList() ?? + [], + difficultyScore: (json['difficultyScore'] as num?)?.toDouble() ?? 0.0, + needsReview: json['needsReview'] as bool? ?? false, + packId: json['packId'] as String?, + ); + +Map _$DetailedWordStatisticsDtoToJson( + DetailedWordStatisticsDto instance) => + { + 'word': instance.word, + 'correct': instance.correct, + 'incorrect': instance.incorrect, + 'skipped': instance.skipped, + 'questionTypes': instance.questionTypes + .map((e) => _$TestQuestionTypeEnumMap[e]) + .toList(), + 'lastReviewed': instance.lastReviewed?.toIso8601String(), + 'firstLearned': instance.firstLearned?.toIso8601String(), + 'recentAttempts': instance.recentAttempts.map((e) => e.toJson()).toList(), + 'difficultyScore': instance.difficultyScore, + 'needsReview': instance.needsReview, + 'packId': instance.packId, + }; + +WordAttemptDto _$WordAttemptDtoFromJson(Map json) => + WordAttemptDto( + timestamp: DateTime.parse(json['timestamp'] as String), + wasCorrect: json['wasCorrect'] as bool, + questionType: $enumDecode(_$TestQuestionTypeEnumMap, json['questionType']), + wasSkipped: json['wasSkipped'] as bool? ?? false, + ); + +Map _$WordAttemptDtoToJson(WordAttemptDto instance) => + { + 'timestamp': instance.timestamp.toIso8601String(), + 'wasCorrect': instance.wasCorrect, + 'questionType': _$TestQuestionTypeEnumMap[instance.questionType], + 'wasSkipped': instance.wasSkipped, + }; + +const _$TestQuestionTypeEnumMap = { + TestQuestionType.simple: 'simple', + TestQuestionType.input_buttons: 'input_buttons', + TestQuestionType.matrix: 'matrix', + TestQuestionType.match: 'match', + TestQuestionType.undefined: 'undefined', +}; diff --git a/mnemo_cards_common/lib/src/dtos/user/data/pack_progress_dto.dart b/mnemo_cards_common/lib/src/dtos/user/data/pack_progress_dto.dart new file mode 100644 index 0000000..4d5663e --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/data/pack_progress_dto.dart @@ -0,0 +1,120 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; + +part 'pack_progress_dto.g.dart'; + + +/// Statistics about user's progress on a specific pack +@JsonSerializable() +@CopyWith() +class PackProgressDto { + /// Pack ID + final String packId; + + /// Total number of cards in the pack + final int totalCards; + + /// Number of cards learned by the user + final int learnedCards; + + /// Total study time spent on this pack in minutes + final int studyTimeMinutes; + + /// Date when user last studied this pack + final DateTime? lastStudyDate; + + /// Date when user first started studying this pack + final DateTime? firstStudyDate; + + /// Map of card ID to number of attempts for that card + final Map cardAttempts; + + /// Average accuracy across all attempts on this pack (0.0 to 1.0) + final double averageAccuracy; + + /// Calculated progress percentage (0.0 to 1.0) + double get progress => totalCards > 0 ? learnedCards / totalCards : 0.0; + + /// Average attempts per card + double get averageAttempts => + cardAttempts.isNotEmpty ? _calculateAverage(cardAttempts.values) : 0.0; + + /// Total attempts across all cards + int get totalAttempts => _calculateSum(cardAttempts.values); + + const PackProgressDto({ + required this.packId, + required this.totalCards, + this.learnedCards = 0, + this.studyTimeMinutes = 0, + this.lastStudyDate, + this.firstStudyDate, + this.cardAttempts = const {}, + this.averageAccuracy = 0.0, + }); + + factory PackProgressDto.fromJson(Map json) => + _$PackProgressDtoFromJson(json); + + Map toJson() => _$PackProgressDtoToJson(this); + + /// Create empty progress for a pack + factory PackProgressDto.empty(String packId, int totalCards) => + PackProgressDto( + packId: packId, + totalCards: totalCards, + ); + + /// Check if user has started studying this pack + bool get hasStarted => learnedCards > 0 || studyTimeMinutes > 0; + + /// Get attempts for a specific card + int getAttemptsForCard(String cardId) => cardAttempts[cardId] ?? 0; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is PackProgressDto && + runtimeType == other.runtimeType && + packId == other.packId && + totalCards == other.totalCards && + learnedCards == other.learnedCards && + studyTimeMinutes == other.studyTimeMinutes && + lastStudyDate == other.lastStudyDate && + firstStudyDate == other.firstStudyDate && + _mapEquals(cardAttempts, other.cardAttempts) && + averageAccuracy == other.averageAccuracy; + + @override + int get hashCode => + packId.hashCode ^ + totalCards.hashCode ^ + learnedCards.hashCode ^ + studyTimeMinutes.hashCode ^ + lastStudyDate.hashCode ^ + firstStudyDate.hashCode ^ + cardAttempts.hashCode ^ + averageAccuracy.hashCode; + + @override + String toString() => 'PackProgressDto(packId: $packId, progress: ${progress.toStringAsFixed(2)}, learned: $learnedCards/$totalCards)'; +} + +// Helper functions +double _calculateAverage(Iterable values) { + if (values.isEmpty) return 0.0; + final sum = values.fold(0, (a, b) => a + b); + return sum / values.length; +} + +int _calculateSum(Iterable values) { + return values.fold(0, (a, b) => a + b); +} + +bool _mapEquals(Map a, Map b) { + if (a.length != b.length) return false; + for (final key in a.keys) { + if (a[key] != b[key]) return false; + } + return true; +} diff --git a/mnemo_cards_common/lib/src/dtos/user/data/pack_progress_dto.g.dart b/mnemo_cards_common/lib/src/dtos/user/data/pack_progress_dto.g.dart new file mode 100644 index 0000000..51f1c13 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/data/pack_progress_dto.g.dart @@ -0,0 +1,38 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'pack_progress_dto.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +PackProgressDto _$PackProgressDtoFromJson(Map json) => + PackProgressDto( + packId: json['packId'] as String, + totalCards: json['totalCards'] as int, + learnedCards: json['learnedCards'] as int? ?? 0, + studyTimeMinutes: json['studyTimeMinutes'] as int? ?? 0, + lastStudyDate: json['lastStudyDate'] == null + ? null + : DateTime.parse(json['lastStudyDate'] as String), + firstStudyDate: json['firstStudyDate'] == null + ? null + : DateTime.parse(json['firstStudyDate'] as String), + cardAttempts: (json['cardAttempts'] as Map?)?.map( + (k, e) => MapEntry(k, e as int), + ) ?? + {}, + averageAccuracy: (json['averageAccuracy'] as num?)?.toDouble() ?? 0.0, + ); + +Map _$PackProgressDtoToJson(PackProgressDto instance) => + { + 'packId': instance.packId, + 'totalCards': instance.totalCards, + 'learnedCards': instance.learnedCards, + 'studyTimeMinutes': instance.studyTimeMinutes, + 'lastStudyDate': instance.lastStudyDate?.toIso8601String(), + 'firstStudyDate': instance.firstStudyDate?.toIso8601String(), + 'cardAttempts': instance.cardAttempts, + 'averageAccuracy': instance.averageAccuracy, + }; diff --git a/mnemo_cards_common/lib/src/dtos/user/data/user_data_dto.dart b/mnemo_cards_common/lib/src/dtos/user/data/user_data_dto.dart new file mode 100644 index 0000000..e63afd8 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/data/user_data_dto.dart @@ -0,0 +1,184 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:mnemo_cards_common/src/dtos/user/data/all_tests_statistics_dto.dart'; +import 'package:mnemo_cards_common/src/dtos/user/achievement_dto.dart'; + +import 'all_words_statistics_dto.dart'; +import 'pack_progress_dto.dart'; + +part 'user_data_dto.g.dart'; + +@JsonSerializable() +@CopyWith() +class UserDataDto { + // Existing fields + final AllWordsStatisticsDto? allWordsStatistics; + final AllTestsStatisticsDto? allTestsStatistics; + + // NEW FIELDS: Extended statistics tracking + + /// When user was last online + final DateTime? lastTimeOnline; + + /// Total study time in minutes across all sessions + final int totalStudyTimeMinutes; + + /// Current streak (consecutive days with study activity) + final int currentStreak; + + /// Longest streak ever achieved + final int longestStreak; + + /// Progress tracking for each pack + final Map packProgress; + + /// List of dates when user studied (for streak calculation) + final List studyDates; + + /// Study time by category/language in minutes + final Map categoryMinutes; + + /// User's achievements + final List achievements; + + UserDataDto({ + this.allWordsStatistics, + this.allTestsStatistics, + this.lastTimeOnline, + this.totalStudyTimeMinutes = 0, + this.currentStreak = 0, + this.longestStreak = 0, + this.packProgress = const {}, + this.studyDates = const [], + this.categoryMinutes = const {}, + this.achievements = const [], + }); + + factory UserDataDto.fromJson(Map json) => + _$UserDataDtoFromJson(json); + + Map toJson() => _$UserDataDtoToJson(this); + + /// Create empty user data + factory UserDataDto.empty() => UserDataDto(); + + /// Get total learned words count + int get totalLearnedWords { + return allWordsStatistics?.words.length ?? 0; + } + + /// Get total completed tests count + int get totalTestsCompleted { + return allTestsStatistics?.tests.length ?? 0; + } + + /// Get total study time as Duration + Duration get totalStudyTime => Duration(minutes: totalStudyTimeMinutes); + + /// Get total study time in hours + double get totalStudyTimeHours => totalStudyTimeMinutes / 60.0; + + /// Get progress for specific pack + PackProgressDto? getPackProgress(String packId) => packProgress[packId]; + + /// Get completed packs count + int get completedPacksCount => + packProgress.values.where((p) => p.progress >= 1.0).length; + + /// Get in-progress packs count + int get inProgressPacksCount => + packProgress.values.where((p) => p.hasStarted && p.progress < 1.0).length; + + /// Get unlocked achievements count + int get unlockedAchievementsCount => + achievements.where((a) => a.isUnlocked).length; + + /// Get total achievements count + int get totalAchievementsCount => achievements.length; + + /// Get recent achievements (last 7 days) + List get recentAchievements { + final weekAgo = DateTime.now().subtract(const Duration(days: 7)); + return achievements + .where((a) => a.isUnlocked && a.unlockedAt!.isAfter(weekAgo)) + .toList(); + } + + /// Check if user is currently on a streak + bool get isOnStreak { + if (studyDates.isEmpty || currentStreak == 0) return false; + final lastStudyDate = studyDates.reduce((a, b) => a.isAfter(b) ? a : b); + final daysSinceLastStudy = DateTime.now().difference(lastStudyDate).inDays; + return daysSinceLastStudy <= 1; // Allow 1 day gap + } + + /// Get streak status message + String get streakStatus { + if (currentStreak == 0) return 'No current streak'; + if (!isOnStreak) return 'Streak broken (${currentStreak} days)'; + return 'Current streak: $currentStreak days'; + } + + /// Get achievement progress summary + Map get achievementsSummary { + final categories = {}; + for (final achievement in achievements.where((a) => a.isUnlocked)) { + categories[achievement.category] = (categories[achievement.category] ?? 0) + 1; + } + return categories; + } + + @override + bool operator ==(Object other) => + identical(this, other) || + other is UserDataDto && + runtimeType == other.runtimeType && + allWordsStatistics == other.allWordsStatistics && + allTestsStatistics == other.allTestsStatistics && + lastTimeOnline == other.lastTimeOnline && + totalStudyTimeMinutes == other.totalStudyTimeMinutes && + currentStreak == other.currentStreak && + longestStreak == other.longestStreak && + _mapEquals(packProgress, other.packProgress) && + _listEquals(studyDates, other.studyDates) && + _mapEqualsStringInt(categoryMinutes, other.categoryMinutes) && + _listEquals(achievements, other.achievements); + + @override + int get hashCode => + allWordsStatistics.hashCode ^ + allTestsStatistics.hashCode ^ + lastTimeOnline.hashCode ^ + totalStudyTimeMinutes.hashCode ^ + currentStreak.hashCode ^ + longestStreak.hashCode ^ + packProgress.hashCode ^ + studyDates.hashCode ^ + categoryMinutes.hashCode ^ + achievements.hashCode; +} + +// Helper functions for equality checks +bool _mapEquals(Map a, Map b) { + if (a.length != b.length) return false; + for (final key in a.keys) { + if (a[key] != b[key]) return false; + } + return true; +} + +bool _mapEqualsStringInt(Map a, Map b) { + if (a.length != b.length) return false; + for (final key in a.keys) { + if (a[key] != b[key]) return false; + } + return true; +} + +bool _listEquals(List a, List b) { + if (a.length != b.length) return false; + for (int i = 0; i < a.length; i++) { + if (a[i] != b[i]) return false; + } + return true; +} diff --git a/mnemo_cards_common/lib/src/dtos/user/data/user_data_dto.g.dart b/mnemo_cards_common/lib/src/dtos/user/data/user_data_dto.g.dart new file mode 100644 index 0000000..d1d49b0 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/data/user_data_dto.g.dart @@ -0,0 +1,90 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'user_data_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$UserDataDtoCWProxy { + UserDataDto allTestsStatistics(AllTestsStatisticsDto? allTestsStatistics); + + UserDataDto allWordsStatistics(AllWordsStatisticsDto? allWordsStatistics); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `UserDataDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// UserDataDto(...).copyWith(id: 12, name: "My name") + /// ```` + UserDataDto call({ + AllTestsStatisticsDto? allTestsStatistics, + AllWordsStatisticsDto? allWordsStatistics, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfUserDataDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfUserDataDto.copyWith.fieldName(...)` +class _$UserDataDtoCWProxyImpl implements _$UserDataDtoCWProxy { + const _$UserDataDtoCWProxyImpl(this._value); + + final UserDataDto _value; + + @override + UserDataDto allTestsStatistics(AllTestsStatisticsDto? allTestsStatistics) => + this(allTestsStatistics: allTestsStatistics); + + @override + UserDataDto allWordsStatistics(AllWordsStatisticsDto? allWordsStatistics) => + this(allWordsStatistics: allWordsStatistics); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `UserDataDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// UserDataDto(...).copyWith(id: 12, name: "My name") + /// ```` + UserDataDto call({ + Object? allTestsStatistics = const $CopyWithPlaceholder(), + Object? allWordsStatistics = const $CopyWithPlaceholder(), + }) { + return UserDataDto( + allTestsStatistics: allTestsStatistics == const $CopyWithPlaceholder() + ? _value.allTestsStatistics + // ignore: cast_nullable_to_non_nullable + : allTestsStatistics as AllTestsStatisticsDto?, + allWordsStatistics: allWordsStatistics == const $CopyWithPlaceholder() + ? _value.allWordsStatistics + // ignore: cast_nullable_to_non_nullable + : allWordsStatistics as AllWordsStatisticsDto?, + ); + } +} + +extension $UserDataDtoCopyWith on UserDataDto { + /// Returns a callable class that can be used as follows: `instanceOfUserDataDto.copyWith(...)` or like so:`instanceOfUserDataDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$UserDataDtoCWProxy get copyWith => _$UserDataDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +UserDataDto _$UserDataDtoFromJson(Map json) => UserDataDto( + allTestsStatistics: json['allTestsStatistics'] == null + ? null + : AllTestsStatisticsDto.fromJson( + json['allTestsStatistics'] as Map), + allWordsStatistics: json['allWordsStatistics'] == null + ? null + : AllWordsStatisticsDto.fromJson( + json['allWordsStatistics'] as Map), + ); + +Map _$UserDataDtoToJson(UserDataDto instance) => + { + 'allWordsStatistics': instance.allWordsStatistics, + 'allTestsStatistics': instance.allTestsStatistics, + }; diff --git a/mnemo_cards_common/lib/src/dtos/user/data/word_statistics_dto.dart b/mnemo_cards_common/lib/src/dtos/user/data/word_statistics_dto.dart new file mode 100644 index 0000000..ed96a2c --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/data/word_statistics_dto.dart @@ -0,0 +1,80 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:mnemo_cards_common/src/utils/json_helper.dart'; + +import '../../game_tests/test_question_type.dart'; +import 'package:collection/collection.dart'; + +part 'word_statistics_dto.g.dart'; + +@JsonSerializable(includeIfNull: false) +@CopyWith() +class WordStatisticsDto { + final String word; + @JsonKey(fromJson: doubleFromJson, toJson: doubleToJson) + final double correct; + @JsonKey(fromJson: doubleFromJson, toJson: doubleToJson) + final double incorrect; + @JsonKey(fromJson: doubleFromJson, toJson: doubleToJson) + final double skipped; + final Set questionTypes; + + @JsonKey(includeFromJson: false, includeToJson: false) + double get total => correct + incorrect + skipped; + + @JsonKey(includeFromJson: false, includeToJson: false) + double get accuracy => total == 0 ? 0.0 : correct / total; + + WordStatisticsDto({ + this.word = '', + this.correct = 0, + this.incorrect = 0, + this.skipped = 0, + this.questionTypes = const {}, + }); + + WordStatisticsDto.empty(this.word) + : correct = 0, + incorrect = 0, + skipped = 0, + questionTypes = {}; + + factory WordStatisticsDto.fromJson(Map json) => + _$WordStatisticsDtoFromJson(json); + + Map toJson() => _$WordStatisticsDtoToJson(this); + + WordStatisticsDto merge(WordStatisticsDto other) { + if (other.word != word) + throw Exception('Cant merge different word statistics'); + return copyWith( + correct: correct + other.correct, + incorrect: incorrect + other.incorrect, + skipped: skipped + other.skipped, + questionTypes: { + ...questionTypes, + ...other.questionTypes, + }, + ); + } + + @override + int get hashCode => + word.hashCode ^ + correct.hashCode ^ + incorrect.hashCode ^ + skipped.hashCode ^ + questionTypes.hashCode; + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is WordStatisticsDto && + other.word == word && + other.correct == correct && + other.incorrect == incorrect && + other.skipped == skipped && + const SetEquality().equals(other.questionTypes, questionTypes); + } +} diff --git a/mnemo_cards_common/lib/src/dtos/user/data/word_statistics_dto.g.dart b/mnemo_cards_common/lib/src/dtos/user/data/word_statistics_dto.g.dart new file mode 100644 index 0000000..b352fdf --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/data/word_statistics_dto.g.dart @@ -0,0 +1,152 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'word_statistics_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$WordStatisticsDtoCWProxy { + WordStatisticsDto word(String word); + + WordStatisticsDto correct(double correct); + + WordStatisticsDto incorrect(double incorrect); + + WordStatisticsDto skipped(double skipped); + + WordStatisticsDto questionTypes(Set questionTypes); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `WordStatisticsDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// WordStatisticsDto(...).copyWith(id: 12, name: "My name") + /// ```` + WordStatisticsDto call({ + String? word, + double? correct, + double? incorrect, + double? skipped, + Set? questionTypes, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfWordStatisticsDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfWordStatisticsDto.copyWith.fieldName(...)` +class _$WordStatisticsDtoCWProxyImpl implements _$WordStatisticsDtoCWProxy { + const _$WordStatisticsDtoCWProxyImpl(this._value); + + final WordStatisticsDto _value; + + @override + WordStatisticsDto word(String word) => this(word: word); + + @override + WordStatisticsDto correct(double correct) => this(correct: correct); + + @override + WordStatisticsDto incorrect(double incorrect) => this(incorrect: incorrect); + + @override + WordStatisticsDto skipped(double skipped) => this(skipped: skipped); + + @override + WordStatisticsDto questionTypes(Set questionTypes) => + this(questionTypes: questionTypes); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `WordStatisticsDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// WordStatisticsDto(...).copyWith(id: 12, name: "My name") + /// ```` + WordStatisticsDto call({ + Object? word = const $CopyWithPlaceholder(), + Object? correct = const $CopyWithPlaceholder(), + Object? incorrect = const $CopyWithPlaceholder(), + Object? skipped = const $CopyWithPlaceholder(), + Object? questionTypes = const $CopyWithPlaceholder(), + }) { + return WordStatisticsDto( + word: word == const $CopyWithPlaceholder() || word == null + ? _value.word + // ignore: cast_nullable_to_non_nullable + : word as String, + correct: correct == const $CopyWithPlaceholder() || correct == null + ? _value.correct + // ignore: cast_nullable_to_non_nullable + : correct as double, + incorrect: incorrect == const $CopyWithPlaceholder() || incorrect == null + ? _value.incorrect + // ignore: cast_nullable_to_non_nullable + : incorrect as double, + skipped: skipped == const $CopyWithPlaceholder() || skipped == null + ? _value.skipped + // ignore: cast_nullable_to_non_nullable + : skipped as double, + questionTypes: + questionTypes == const $CopyWithPlaceholder() || questionTypes == null + ? _value.questionTypes + // ignore: cast_nullable_to_non_nullable + : questionTypes as Set, + ); + } +} + +extension $WordStatisticsDtoCopyWith on WordStatisticsDto { + /// Returns a callable class that can be used as follows: `instanceOfWordStatisticsDto.copyWith(...)` or like so:`instanceOfWordStatisticsDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$WordStatisticsDtoCWProxy get copyWith => + _$WordStatisticsDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +WordStatisticsDto _$WordStatisticsDtoFromJson(Map json) => + WordStatisticsDto( + word: json['word'] as String? ?? '', + correct: json['correct'] == null + ? 0 + : doubleFromJson(json['correct'] as double?), + incorrect: json['incorrect'] == null + ? 0 + : doubleFromJson(json['incorrect'] as double?), + skipped: json['skipped'] == null + ? 0 + : doubleFromJson(json['skipped'] as double?), + questionTypes: (json['questionTypes'] as List?) + ?.map((e) => $enumDecode(_$TestQuestionTypeEnumMap, e)) + .toSet() ?? + const {}, + ); + +Map _$WordStatisticsDtoToJson(WordStatisticsDto instance) { + final val = { + 'word': instance.word, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('correct', doubleToJson(instance.correct)); + writeNotNull('incorrect', doubleToJson(instance.incorrect)); + writeNotNull('skipped', doubleToJson(instance.skipped)); + val['questionTypes'] = + instance.questionTypes.map((e) => _$TestQuestionTypeEnumMap[e]!).toList(); + return val; +} + +const _$TestQuestionTypeEnumMap = { + TestQuestionType.simple: 'simple', + TestQuestionType.input_buttons: 'input_buttons', + TestQuestionType.matrix: 'matrix', + TestQuestionType.match: 'match', + TestQuestionType.undefined: 'undefined', +}; diff --git a/mnemo_cards_common/lib/src/dtos/user/enums.dart b/mnemo_cards_common/lib/src/dtos/user/enums.dart new file mode 100644 index 0000000..577d224 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/enums.dart @@ -0,0 +1 @@ +enum ExternalIdType { google, telegram, device } diff --git a/mnemo_cards_common/lib/src/dtos/user/promo_code_dto.dart b/mnemo_cards_common/lib/src/dtos/user/promo_code_dto.dart new file mode 100644 index 0000000..d7b0635 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/promo_code_dto.dart @@ -0,0 +1,23 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; + +part 'promo_code_dto.g.dart'; + +@JsonSerializable() +@CopyWith() +class PromoCodeDto { + final String? code; + final String? message; + final bool? success; + + const PromoCodeDto({ + this.code, + this.message, + this.success, + }); + + factory PromoCodeDto.fromJson(Map json) => + _$PromoCodeDtoFromJson(json); + + Map toJson() => _$PromoCodeDtoToJson(this); +} diff --git a/mnemo_cards_common/lib/src/dtos/user/promo_code_dto.g.dart b/mnemo_cards_common/lib/src/dtos/user/promo_code_dto.g.dart new file mode 100644 index 0000000..051b833 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/promo_code_dto.g.dart @@ -0,0 +1,95 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'promo_code_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$PromoCodeDtoCWProxy { + PromoCodeDto code(String? code); + + PromoCodeDto message(String? message); + + PromoCodeDto success(bool? success); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `PromoCodeDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// PromoCodeDto(...).copyWith(id: 12, name: "My name") + /// ```` + PromoCodeDto call({ + String? code, + String? message, + bool? success, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfPromoCodeDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfPromoCodeDto.copyWith.fieldName(...)` +class _$PromoCodeDtoCWProxyImpl implements _$PromoCodeDtoCWProxy { + const _$PromoCodeDtoCWProxyImpl(this._value); + + final PromoCodeDto _value; + + @override + PromoCodeDto code(String? code) => this(code: code); + + @override + PromoCodeDto message(String? message) => this(message: message); + + @override + PromoCodeDto success(bool? success) => this(success: success); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `PromoCodeDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// PromoCodeDto(...).copyWith(id: 12, name: "My name") + /// ```` + PromoCodeDto call({ + Object? code = const $CopyWithPlaceholder(), + Object? message = const $CopyWithPlaceholder(), + Object? success = const $CopyWithPlaceholder(), + }) { + return PromoCodeDto( + code: code == const $CopyWithPlaceholder() + ? _value.code + // ignore: cast_nullable_to_non_nullable + : code as String?, + message: message == const $CopyWithPlaceholder() + ? _value.message + // ignore: cast_nullable_to_non_nullable + : message as String?, + success: success == const $CopyWithPlaceholder() + ? _value.success + // ignore: cast_nullable_to_non_nullable + : success as bool?, + ); + } +} + +extension $PromoCodeDtoCopyWith on PromoCodeDto { + /// Returns a callable class that can be used as follows: `instanceOfPromoCodeDto.copyWith(...)` or like so:`instanceOfPromoCodeDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$PromoCodeDtoCWProxy get copyWith => _$PromoCodeDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +PromoCodeDto _$PromoCodeDtoFromJson(Map json) => PromoCodeDto( + code: json['code'] as String?, + message: json['message'] as String?, + success: json['success'] as bool?, + ); + +Map _$PromoCodeDtoToJson(PromoCodeDto instance) => + { + 'code': instance.code, + 'message': instance.message, + 'success': instance.success, + }; diff --git a/mnemo_cards_common/lib/src/dtos/user/settings/user_settings_dto.dart b/mnemo_cards_common/lib/src/dtos/user/settings/user_settings_dto.dart new file mode 100644 index 0000000..c4e4420 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/settings/user_settings_dto.dart @@ -0,0 +1,31 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; + +part 'user_settings_dto.g.dart'; + +@JsonSerializable() +@CopyWith() +class UserSettingsDto { + final Map packCardsOrder; + + UserSettingsDto({this.packCardsOrder = const {}}); + + factory UserSettingsDto.fromJson(Map json) => + _$UserSettingsDtoFromJson(json); + + Map toJson() => _$UserSettingsDtoToJson(this); +} + +@JsonSerializable() +@CopyWith() +class PackCardsOrderDto { + final int packId; + final List cardsOrder; + + PackCardsOrderDto({this.packId = -1, this.cardsOrder = const []}); + + factory PackCardsOrderDto.fromJson(Map json) => + _$PackCardsOrderDtoFromJson(json); + + Map toJson() => _$PackCardsOrderDtoToJson(this); +} diff --git a/mnemo_cards_common/lib/src/dtos/user/settings/user_settings_dto.g.dart b/mnemo_cards_common/lib/src/dtos/user/settings/user_settings_dto.g.dart new file mode 100644 index 0000000..609b54c --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/settings/user_settings_dto.g.dart @@ -0,0 +1,155 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'user_settings_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$UserSettingsDtoCWProxy { + UserSettingsDto packCardsOrder(Map packCardsOrder); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `UserSettingsDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// UserSettingsDto(...).copyWith(id: 12, name: "My name") + /// ```` + UserSettingsDto call({ + Map? packCardsOrder, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfUserSettingsDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfUserSettingsDto.copyWith.fieldName(...)` +class _$UserSettingsDtoCWProxyImpl implements _$UserSettingsDtoCWProxy { + const _$UserSettingsDtoCWProxyImpl(this._value); + + final UserSettingsDto _value; + + @override + UserSettingsDto packCardsOrder(Map packCardsOrder) => + this(packCardsOrder: packCardsOrder); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `UserSettingsDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// UserSettingsDto(...).copyWith(id: 12, name: "My name") + /// ```` + UserSettingsDto call({ + Object? packCardsOrder = const $CopyWithPlaceholder(), + }) { + return UserSettingsDto( + packCardsOrder: packCardsOrder == const $CopyWithPlaceholder() || + packCardsOrder == null + ? _value.packCardsOrder + // ignore: cast_nullable_to_non_nullable + : packCardsOrder as Map, + ); + } +} + +extension $UserSettingsDtoCopyWith on UserSettingsDto { + /// Returns a callable class that can be used as follows: `instanceOfUserSettingsDto.copyWith(...)` or like so:`instanceOfUserSettingsDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$UserSettingsDtoCWProxy get copyWith => _$UserSettingsDtoCWProxyImpl(this); +} + +abstract class _$PackCardsOrderDtoCWProxy { + PackCardsOrderDto packId(int packId); + + PackCardsOrderDto cardsOrder(List cardsOrder); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `PackCardsOrderDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// PackCardsOrderDto(...).copyWith(id: 12, name: "My name") + /// ```` + PackCardsOrderDto call({ + int? packId, + List? cardsOrder, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfPackCardsOrderDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfPackCardsOrderDto.copyWith.fieldName(...)` +class _$PackCardsOrderDtoCWProxyImpl implements _$PackCardsOrderDtoCWProxy { + const _$PackCardsOrderDtoCWProxyImpl(this._value); + + final PackCardsOrderDto _value; + + @override + PackCardsOrderDto packId(int packId) => this(packId: packId); + + @override + PackCardsOrderDto cardsOrder(List cardsOrder) => + this(cardsOrder: cardsOrder); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `PackCardsOrderDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// PackCardsOrderDto(...).copyWith(id: 12, name: "My name") + /// ```` + PackCardsOrderDto call({ + Object? packId = const $CopyWithPlaceholder(), + Object? cardsOrder = const $CopyWithPlaceholder(), + }) { + return PackCardsOrderDto( + packId: packId == const $CopyWithPlaceholder() || packId == null + ? _value.packId + // ignore: cast_nullable_to_non_nullable + : packId as int, + cardsOrder: + cardsOrder == const $CopyWithPlaceholder() || cardsOrder == null + ? _value.cardsOrder + // ignore: cast_nullable_to_non_nullable + : cardsOrder as List, + ); + } +} + +extension $PackCardsOrderDtoCopyWith on PackCardsOrderDto { + /// Returns a callable class that can be used as follows: `instanceOfPackCardsOrderDto.copyWith(...)` or like so:`instanceOfPackCardsOrderDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$PackCardsOrderDtoCWProxy get copyWith => + _$PackCardsOrderDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +UserSettingsDto _$UserSettingsDtoFromJson(Map json) => + UserSettingsDto( + packCardsOrder: (json['packCardsOrder'] as Map?)?.map( + (k, e) => MapEntry(int.parse(k), + PackCardsOrderDto.fromJson(e as Map)), + ) ?? + const {}, + ); + +Map _$UserSettingsDtoToJson(UserSettingsDto instance) => + { + 'packCardsOrder': + instance.packCardsOrder.map((k, e) => MapEntry(k.toString(), e)), + }; + +PackCardsOrderDto _$PackCardsOrderDtoFromJson(Map json) => + PackCardsOrderDto( + packId: json['packId'] as int? ?? -1, + cardsOrder: (json['cardsOrder'] as List?) + ?.map((e) => e as int) + .toList() ?? + const [], + ); + +Map _$PackCardsOrderDtoToJson(PackCardsOrderDto instance) => + { + 'packId': instance.packId, + 'cardsOrder': instance.cardsOrder, + }; diff --git a/mnemo_cards_common/lib/src/dtos/user/study_session_dto.dart b/mnemo_cards_common/lib/src/dtos/user/study_session_dto.dart new file mode 100644 index 0000000..e953144 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/study_session_dto.dart @@ -0,0 +1,237 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; + +part 'study_session_dto.g.dart'; + +/// Study session data for tracking learning activity +@JsonSerializable() +@CopyWith() +class StudySessionDto { + /// Unique session identifier + final String? sessionId; + + /// When the session started + final DateTime startTime; + + /// When the session ended (null if still active) + final DateTime? endTime; + + /// Number of words learned during this session + final int wordsLearned; + + /// Number of tests completed during this session + final int testsCompleted; + + /// Overall accuracy during this session (0.0 to 1.0) + final double accuracy; + + /// Pack being studied (if focused on specific pack) + final String? packId; + + /// Test being taken (if part of a test) + final String? testId; + + StudySessionDto({ + this.sessionId, + required this.startTime, + this.endTime, + this.wordsLearned = 0, + this.testsCompleted = 0, + this.accuracy = 0.0, + this.packId, + this.testId, + }); + + factory StudySessionDto.fromJson(Map json) => + _$StudySessionDtoFromJson(json); + + Map toJson() => _$StudySessionDtoToJson(this); + + /// Check if session is currently active + bool get isActive => endTime == null; + + /// Get session duration in minutes + Duration get duration { + final end = endTime ?? DateTime.now(); + return end.difference(startTime); + } + + /// Get session duration in minutes (integer) + int get durationMinutes => duration.inMinutes; + + /// Create new session + factory StudySessionDto.start({ + String? sessionId, + String? packId, + String? testId, + }) => StudySessionDto( + sessionId: sessionId ?? _generateSessionId(), + startTime: DateTime.now(), + packId: packId, + testId: testId, + ); + + /// End the session with final statistics + StudySessionDto end({ + int wordsLearned = 0, + int testsCompleted = 0, + double accuracy = 0.0, + }) => StudySessionDto( + sessionId: sessionId, + startTime: startTime, + endTime: DateTime.now(), + wordsLearned: wordsLearned, + testsCompleted: testsCompleted, + accuracy: accuracy, + packId: packId, + testId: testId, + ); + + /// Add progress to active session + StudySessionDto addProgress({ + int wordsLearned = 0, + int testsCompleted = 0, + double? accuracy, + }) => StudySessionDto( + sessionId: sessionId, + startTime: startTime, + endTime: endTime, + wordsLearned: this.wordsLearned + wordsLearned, + testsCompleted: this.testsCompleted + testsCompleted, + accuracy: accuracy ?? this.accuracy, + packId: packId, + testId: testId, + ); + + /// Get session type description + String get sessionType { + if (testId != null) return 'Test Session'; + if (packId != null) return 'Pack Study'; + return 'General Study'; + } + + /// Get productivity score (words per minute) + double get productivityScore { + final minutes = duration.inMinutes; + if (minutes == 0) return 0.0; + return wordsLearned / minutes; + } + + /// Check if session was productive + bool get isProductive { + return wordsLearned >= 5 && accuracy >= 0.7 && duration.inMinutes >= 5; + } + + static String _generateSessionId() => + 'session_${DateTime.now().millisecondsSinceEpoch}_${DateTime.now().microsecond}'; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is StudySessionDto && + runtimeType == other.runtimeType && + sessionId == other.sessionId && + startTime == other.startTime && + endTime == other.endTime && + wordsLearned == other.wordsLearned && + testsCompleted == other.testsCompleted && + accuracy == other.accuracy && + packId == other.packId && + testId == other.testId; + + @override + int get hashCode => + sessionId.hashCode ^ + startTime.hashCode ^ + endTime.hashCode ^ + wordsLearned.hashCode ^ + testsCompleted.hashCode ^ + accuracy.hashCode ^ + packId.hashCode ^ + testId.hashCode; + + @override + String toString() => + 'StudySessionDto(id: $sessionId, duration: ${duration.inMinutes}min, words: $wordsLearned, accuracy: ${(accuracy * 100).toStringAsFixed(1)}%, type: $sessionType)'; +} + +/// Study session summary for aggregated statistics +class StudySessionSummary { + final int totalSessions; + final Duration totalTime; + final int totalWordsLearned; + final int totalTestsCompleted; + final double averageAccuracy; + final double averageProductivity; + + const StudySessionSummary({ + required this.totalSessions, + required this.totalTime, + required this.totalWordsLearned, + required this.totalTestsCompleted, + required this.averageAccuracy, + required this.averageProductivity, + }); + + factory StudySessionSummary.fromSessions(List sessions) { + if (sessions.isEmpty) { + return const StudySessionSummary( + totalSessions: 0, + totalTime: Duration.zero, + totalWordsLearned: 0, + totalTestsCompleted: 0, + averageAccuracy: 0.0, + averageProductivity: 0.0, + ); + } + + final totalTime = sessions.fold( + Duration.zero, + (sum, session) => sum + session.duration, + ); + + final totalWordsLearned = sessions.fold( + 0, + (sum, session) => sum + session.wordsLearned, + ); + + final totalTestsCompleted = sessions.fold( + 0, + (sum, session) => sum + session.testsCompleted, + ); + + final totalAccuracy = sessions.fold( + 0, + (sum, session) => sum + session.accuracy, + ); + + final totalProductivity = sessions.fold( + 0, + (sum, session) => sum + session.productivityScore, + ); + + return StudySessionSummary( + totalSessions: sessions.length, + totalTime: totalTime, + totalWordsLearned: totalWordsLearned, + totalTestsCompleted: totalTestsCompleted, + averageAccuracy: totalAccuracy / sessions.length, + averageProductivity: totalProductivity / sessions.length, + ); + } + + /// Get average session duration + Duration get averageSessionDuration => + totalSessions > 0 ? totalTime ~/ totalSessions : Duration.zero; + + /// Get average words per session + double get averageWordsPerSession => + totalSessions > 0 ? totalWordsLearned / totalSessions : 0.0; + + /// Get total study time in hours + double get totalHours => totalTime.inMinutes / 60.0; + + @override + String toString() => + 'StudySessionSummary(sessions: $totalSessions, time: ${totalHours.toStringAsFixed(1)}h, words: $totalWordsLearned, accuracy: ${(averageAccuracy * 100).toStringAsFixed(1)}%)'; +} diff --git a/mnemo_cards_common/lib/src/dtos/user/study_session_dto.g.dart b/mnemo_cards_common/lib/src/dtos/user/study_session_dto.g.dart new file mode 100644 index 0000000..b76462c --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/study_session_dto.g.dart @@ -0,0 +1,33 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'study_session_dto.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +StudySessionDto _$StudySessionDtoFromJson(Map json) => + StudySessionDto( + sessionId: json['sessionId'] as String?, + startTime: DateTime.parse(json['startTime'] as String), + endTime: json['endTime'] == null + ? null + : DateTime.parse(json['endTime'] as String), + wordsLearned: json['wordsLearned'] as int? ?? 0, + testsCompleted: json['testsCompleted'] as int? ?? 0, + accuracy: (json['accuracy'] as num?)?.toDouble() ?? 0.0, + packId: json['packId'] as String?, + testId: json['testId'] as String?, + ); + +Map _$StudySessionDtoToJson(StudySessionDto instance) => + { + 'sessionId': instance.sessionId, + 'startTime': instance.startTime.toIso8601String(), + 'endTime': instance.endTime?.toIso8601String(), + 'wordsLearned': instance.wordsLearned, + 'testsCompleted': instance.testsCompleted, + 'accuracy': instance.accuracy, + 'packId': instance.packId, + 'testId': instance.testId, + }; diff --git a/mnemo_cards_common/lib/src/dtos/user/user_dto.dart b/mnemo_cards_common/lib/src/dtos/user/user_dto.dart new file mode 100644 index 0000000..327c811 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/user_dto.dart @@ -0,0 +1,49 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:mnemo_cards_common/src/dtos/user/settings/user_settings_dto.dart'; + +import '../subscription/subscription_features.dart'; +import 'data/user_data_dto.dart'; + +part 'user_dto.g.dart'; + +@JsonSerializable() +@CopyWith() +class UserDto { + int? id; + final String? name; + final String? email; + final bool admin; + final List packs; + final List purchases; + final bool? subscription; + final Set subscriptionFeatures; + + final UserDataDto? userDataDto; + final UserSettingsDto? userSettingsDto; + + UserDto({ + this.id, + this.name, + this.email, + this.admin = false, + this.packs = const [], + this.subscription = false, + this.subscriptionFeatures = const {}, + this.purchases = const [], + this.userDataDto, + this.userSettingsDto, + }); + + factory UserDto.fromJson(Map json) => + _$UserDtoFromJson(json); + + Map toJson() => _$UserDtoToJson(this); + + static UserDto get empty => UserDto( + admin: false, + packs: [], + subscription: false, + purchases: [], + ); +} diff --git a/mnemo_cards_common/lib/src/dtos/user/user_dto.g.dart b/mnemo_cards_common/lib/src/dtos/user/user_dto.g.dart new file mode 100644 index 0000000..cb473e1 --- /dev/null +++ b/mnemo_cards_common/lib/src/dtos/user/user_dto.g.dart @@ -0,0 +1,213 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'user_dto.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$UserDtoCWProxy { + UserDto id(int? id); + + UserDto name(String? name); + + UserDto email(String? email); + + UserDto admin(bool admin); + + UserDto packs(List packs); + + UserDto subscription(bool? subscription); + + UserDto subscriptionFeatures( + Set subscriptionFeatures); + + UserDto purchases(List purchases); + + UserDto userDataDto(UserDataDto? userDataDto); + + UserDto userSettingsDto(UserSettingsDto? userSettingsDto); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `UserDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// UserDto(...).copyWith(id: 12, name: "My name") + /// ```` + UserDto call({ + int? id, + String? name, + String? email, + bool? admin, + List? packs, + bool? subscription, + Set? subscriptionFeatures, + List? purchases, + UserDataDto? userDataDto, + UserSettingsDto? userSettingsDto, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfUserDto.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfUserDto.copyWith.fieldName(...)` +class _$UserDtoCWProxyImpl implements _$UserDtoCWProxy { + const _$UserDtoCWProxyImpl(this._value); + + final UserDto _value; + + @override + UserDto id(int? id) => this(id: id); + + @override + UserDto name(String? name) => this(name: name); + + @override + UserDto email(String? email) => this(email: email); + + @override + UserDto admin(bool admin) => this(admin: admin); + + @override + UserDto packs(List packs) => this(packs: packs); + + @override + UserDto subscription(bool? subscription) => this(subscription: subscription); + + @override + UserDto subscriptionFeatures( + Set subscriptionFeatures) => + this(subscriptionFeatures: subscriptionFeatures); + + @override + UserDto purchases(List purchases) => this(purchases: purchases); + + @override + UserDto userDataDto(UserDataDto? userDataDto) => + this(userDataDto: userDataDto); + + @override + UserDto userSettingsDto(UserSettingsDto? userSettingsDto) => + this(userSettingsDto: userSettingsDto); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `UserDto(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// UserDto(...).copyWith(id: 12, name: "My name") + /// ```` + UserDto call({ + Object? id = const $CopyWithPlaceholder(), + Object? name = const $CopyWithPlaceholder(), + Object? email = const $CopyWithPlaceholder(), + Object? admin = const $CopyWithPlaceholder(), + Object? packs = const $CopyWithPlaceholder(), + Object? subscription = const $CopyWithPlaceholder(), + Object? subscriptionFeatures = const $CopyWithPlaceholder(), + Object? purchases = const $CopyWithPlaceholder(), + Object? userDataDto = const $CopyWithPlaceholder(), + Object? userSettingsDto = const $CopyWithPlaceholder(), + }) { + return UserDto( + id: id == const $CopyWithPlaceholder() + ? _value.id + // ignore: cast_nullable_to_non_nullable + : id as int?, + name: name == const $CopyWithPlaceholder() + ? _value.name + // ignore: cast_nullable_to_non_nullable + : name as String?, + email: email == const $CopyWithPlaceholder() + ? _value.email + // ignore: cast_nullable_to_non_nullable + : email as String?, + admin: admin == const $CopyWithPlaceholder() || admin == null + ? _value.admin + // ignore: cast_nullable_to_non_nullable + : admin as bool, + packs: packs == const $CopyWithPlaceholder() || packs == null + ? _value.packs + // ignore: cast_nullable_to_non_nullable + : packs as List, + subscription: subscription == const $CopyWithPlaceholder() + ? _value.subscription + // ignore: cast_nullable_to_non_nullable + : subscription as bool?, + subscriptionFeatures: + subscriptionFeatures == const $CopyWithPlaceholder() || + subscriptionFeatures == null + ? _value.subscriptionFeatures + // ignore: cast_nullable_to_non_nullable + : subscriptionFeatures as Set, + purchases: purchases == const $CopyWithPlaceholder() || purchases == null + ? _value.purchases + // ignore: cast_nullable_to_non_nullable + : purchases as List, + userDataDto: userDataDto == const $CopyWithPlaceholder() + ? _value.userDataDto + // ignore: cast_nullable_to_non_nullable + : userDataDto as UserDataDto?, + userSettingsDto: userSettingsDto == const $CopyWithPlaceholder() + ? _value.userSettingsDto + // ignore: cast_nullable_to_non_nullable + : userSettingsDto as UserSettingsDto?, + ); + } +} + +extension $UserDtoCopyWith on UserDto { + /// Returns a callable class that can be used as follows: `instanceOfUserDto.copyWith(...)` or like so:`instanceOfUserDto.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$UserDtoCWProxy get copyWith => _$UserDtoCWProxyImpl(this); +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +UserDto _$UserDtoFromJson(Map json) => UserDto( + id: json['id'] as int?, + name: json['name'] as String?, + email: json['email'] as String?, + admin: json['admin'] as bool? ?? false, + packs: + (json['packs'] as List?)?.map((e) => e as String).toList() ?? + const [], + subscription: json['subscription'] as bool? ?? false, + subscriptionFeatures: (json['subscriptionFeatures'] as List?) + ?.map((e) => $enumDecode(_$SubscriptionFeatureEnumEnumMap, e)) + .toSet() ?? + const {}, + purchases: (json['purchases'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + userDataDto: json['userDataDto'] == null + ? null + : UserDataDto.fromJson(json['userDataDto'] as Map), + userSettingsDto: json['userSettingsDto'] == null + ? null + : UserSettingsDto.fromJson( + json['userSettingsDto'] as Map), + ); + +Map _$UserDtoToJson(UserDto instance) => { + 'id': instance.id, + 'name': instance.name, + 'email': instance.email, + 'admin': instance.admin, + 'packs': instance.packs, + 'purchases': instance.purchases, + 'subscription': instance.subscription, + 'subscriptionFeatures': instance.subscriptionFeatures + .map((e) => _$SubscriptionFeatureEnumEnumMap[e]!) + .toList(), + 'userDataDto': instance.userDataDto, + 'userSettingsDto': instance.userSettingsDto, + }; + +const _$SubscriptionFeatureEnumEnumMap = { + SubscriptionFeatureEnum.ads: 'ads', + SubscriptionFeatureEnum.packs: 'packs', + SubscriptionFeatureEnum.unknown: 'unknown', +}; diff --git a/mnemo_cards_common/lib/src/utils/iterable_helper.dart b/mnemo_cards_common/lib/src/utils/iterable_helper.dart new file mode 100644 index 0000000..f0fc89f --- /dev/null +++ b/mnemo_cards_common/lib/src/utils/iterable_helper.dart @@ -0,0 +1,66 @@ +extension IterableHelper on Iterable { + T? firstWhereOrNull(bool Function(T) test) => where(test).firstOrNull; +} + +extension NullableIterableHelper on Iterable { + Iterable whereNotNull() => where((element) => element != null).cast(); + + bool hasIntersection(Iterable other) { + for (final value in other) { + if (contains(value)) { + return true; + } + } + return false; + } +} + +extension ListHelper on List { + // List shuffle([int? seed]) { + // Random r = Random(seed); + // var items = [...this]; + // for (var i = length - 1; i > 0; i--) { + // var n = r.nextInt(i + 1); + // + // var temp = items[i]; + // items[i] = items[n]; + // items[n] = temp; + // } + // + // return items; + // } + + void move(int from, int to) { + RangeError.checkValidIndex(from, this, "from", length); + RangeError.checkValidIndex(to, this, "to", length); + var element = this[from]; + if (from < to) { + setRange(from, to, this, from + 1); + } else { + setRange(to + 1, from + 1, this, to); + } + this[to] = element; + } + + void sortInOrder

(List

order, P valueGetter(T v)) => sort((p, n) { + final pVal = valueGetter(p); + final nVal = valueGetter(n); + final pIndex = order.indexOf(pVal); + final nIndex = order.indexOf(nVal); + if (pIndex == -1) { + return nIndex == -1 + ? () { + if (pVal is num) { + return pVal.compareTo(nVal as num); + } else if (pVal is String) { + return pVal.compareTo(nVal as String); + } + return pVal.toString().compareTo(nVal.toString()); + }.call() + : 1; + } else if (nIndex == -1) { + return -1; + } + return pIndex.compareTo(nIndex); + }); +} diff --git a/mnemo_cards_common/lib/src/utils/json_helper.dart b/mnemo_cards_common/lib/src/utils/json_helper.dart new file mode 100644 index 0000000..f1d8106 --- /dev/null +++ b/mnemo_cards_common/lib/src/utils/json_helper.dart @@ -0,0 +1,3 @@ +double? doubleToJson(double a) => a == 0 ? null : a; + +double doubleFromJson(double? a) => a ?? 0.0; diff --git a/mnemo_cards_common/lib/src/utils/token_generator.dart b/mnemo_cards_common/lib/src/utils/token_generator.dart new file mode 100644 index 0000000..55c9adb --- /dev/null +++ b/mnemo_cards_common/lib/src/utils/token_generator.dart @@ -0,0 +1,61 @@ +import 'dart:convert'; + +import 'package:crypto/crypto.dart' as crypto; +import 'package:version/version.dart'; + +class TokenGenerator { + static final _legacyRequestSalt = 'fklgjadlfk567dv'.hashCode; + static final _requestSalt = '169323236632387788045416'; + static final _archiveSalt = 'sadfghc8azXVdbjZqTaa0d1r9YDgKQj88HHedfvgbgnRf'; + + static String? generateRequestToken({ + required String requestBody, + required String requestPath, + required String appVersion, + String? userToken, + }) { + final version = Version.parse(appVersion); + print( + 'Generating token: ${requestBody} ${requestPath} ${appVersion} ${userToken}'); + if (version == Version.parse('1.0.0')) { + return null; + } + if (requestPath.contains('user')) { + userToken = null; + } + if (version < Version.parse('1.1.0')) { + final requestString = + '${requestBody}_${appVersion}_${userToken}_${requestPath}_${_legacyRequestSalt}' + .replaceAll( + RegExp('[^A-Za-z0-9_]'), + '', + ); + final bytes = utf8.encode(requestString); + return crypto.sha256.convert(bytes).toString(); + } + if (version >= Version.parse('1.1.0')) { + final requestString = '${requestBody}_${appVersion}_${userToken}_${requestPath}_${_requestSalt}' + .replaceAll( + RegExp('[^A-Za-z0-9_]'), + '', + ); + final bytes = utf8.encode(requestString); + return crypto.sha256.convert(bytes).toString(); + } + return null; + } + + static String? generateArchivePassword({ + required String appVersion, + required String id, + }) { + final version = Version.parse(appVersion); + if (version == Version.parse('1.0.0')) { + return null; + } + final bytes = utf8.encode( + '${appVersion}_${id}_${_archiveSalt}', + ); + return crypto.sha256.convert(bytes).toString(); + } +} diff --git a/mnemo_cards_common/lib/src/utils/utils.dart b/mnemo_cards_common/lib/src/utils/utils.dart new file mode 100644 index 0000000..f7f517b --- /dev/null +++ b/mnemo_cards_common/lib/src/utils/utils.dart @@ -0,0 +1,74 @@ +import 'dart:convert'; +import 'dart:math'; + +import 'package:mnemo_cards_common/mnemo_cards_common.dart'; + +extension X on T { + R let(R Function(T) foo) => foo(this); + + C as() => this as C; + + C? tryAs() => this is C ? this as C : null; +} + +extension JsonExt on T { + String encode() => jsonEncode(this); +} + +extension JsonStringExt on String { + T decode([T Function(Map)? fromJson]) => fromJson == null + ? jsonDecode(this) as T + : fromJson.call(jsonDecode(this)); + + List decodeList([T Function(Map)? fromJson]) { + final json = jsonDecode(this.startsWith('[') ? this : '[$this]'); + json as Iterable; + return json + .map((item) => fromJson == null ? item as T : fromJson(item)) + .toList(); + } + + T? tryDecode([T Function(Map)? fromJson]) { + try { + return decode(fromJson); + } catch (e) { + return null; + } + } +} + +extension ListExt on List { + List takeLast(int v) => reversed.take(v).toList(); +} + +extension StringExt on String { + String takeLast(int v) => substring(max(length - v, 0)); + + String take(int v) => substring(0, min(length, v)); + + T? toEnum(List values) => + values.firstWhereOrNull((v) => v.name == this); + + String? get notEmptyOrNull => isEmpty ? null : this; +} + +extension DateTimeExt on DateTime { + bool isBetween(DateTime from, DateTime to) { + if (from.isBefore(to)) { + return isBefore(to) && isAfter(from); + } + if (from.isAtSameMomentAs(to)) { + return isAtSameMomentAs(from); + } + return isBetween(to, from); + } +} + +extension DurationExt on Duration { + Duration operator /(num value) => + Duration(microseconds: (inMicroseconds / value).floor()); + + Duration operator *(num value) => + Duration(microseconds: (inMicroseconds * value).floor()); +} + diff --git a/mnemo_cards_common/lib/src/utils/word_statistics.dart b/mnemo_cards_common/lib/src/utils/word_statistics.dart new file mode 100644 index 0000000..49cabef --- /dev/null +++ b/mnemo_cards_common/lib/src/utils/word_statistics.dart @@ -0,0 +1,9 @@ +import 'package:mnemo_cards_common/mnemo_cards_common.dart'; + +extension WordStatisticsModelDto on Iterable { + double get correct => fold(0, (s, v) => s + v.correct); + + double get incorrect => fold(0, (s, v) => s + v.incorrect); + + double get skipped => fold(0, (s, v) => s + v.skipped); +} diff --git a/mnemo_cards_common/pubspec.lock b/mnemo_cards_common/pubspec.lock new file mode 100644 index 0000000..eb49b82 --- /dev/null +++ b/mnemo_cards_common/pubspec.lock @@ -0,0 +1,477 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + sha256: eb376e9acf6938204f90eb3b1f00b578640d3188b4c8a8ec054f9f479af8d051 + url: "https://pub.dev" + source: hosted + version: "64.0.0" + analyzer: + dependency: transitive + description: + name: analyzer + sha256: "69f54f967773f6c26c7dcb13e93d7ccee8b17a641689da39e878d5cf13b06893" + url: "https://pub.dev" + source: hosted + version: "6.2.0" + args: + dependency: transitive + description: + name: args + sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 + url: "https://pub.dev" + source: hosted + version: "2.4.2" + async: + dependency: transitive + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + build: + dependency: transitive + description: + name: build + sha256: "80184af8b6cb3e5c1c4ec6d8544d27711700bc3e6d2efad04238c7b5290889f0" + url: "https://pub.dev" + source: hosted + version: "2.4.1" + build_config: + dependency: transitive + description: + name: build_config + sha256: bf80fcfb46a29945b423bd9aad884590fb1dc69b330a4d4700cac476af1708d1 + url: "https://pub.dev" + source: hosted + version: "1.1.1" + build_daemon: + dependency: transitive + description: + name: build_daemon + sha256: "0343061a33da9c5810b2d6cee51945127d8f4c060b7fbdd9d54917f0a3feaaa1" + url: "https://pub.dev" + source: hosted + version: "4.0.1" + build_resolvers: + dependency: transitive + description: + name: build_resolvers + sha256: "339086358431fa15d7eca8b6a36e5d783728cf025e559b834f4609a1fcfb7b0a" + url: "https://pub.dev" + source: hosted + version: "2.4.2" + build_runner: + dependency: "direct dev" + description: + name: build_runner + sha256: "581bacf68f89ec8792f5e5a0b2c4decd1c948e97ce659dc783688c8a88fbec21" + url: "https://pub.dev" + source: hosted + version: "2.4.8" + build_runner_core: + dependency: transitive + description: + name: build_runner_core + sha256: "4ae8ffe5ac758da294ecf1802f2aff01558d8b1b00616aa7538ea9a8a5d50799" + url: "https://pub.dev" + source: hosted + version: "7.3.0" + built_collection: + dependency: transitive + description: + name: built_collection + sha256: "376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100" + url: "https://pub.dev" + source: hosted + version: "5.1.1" + built_value: + dependency: transitive + description: + name: built_value + sha256: a3ec2e0f967bc47f69f95009bb93db936288d61d5343b9436e378b28a2f830c6 + url: "https://pub.dev" + source: hosted + version: "8.9.0" + checked_yaml: + dependency: transitive + description: + name: checked_yaml + sha256: feb6bed21949061731a7a75fc5d2aa727cf160b91af9a3e464c5e3a32e28b5ff + url: "https://pub.dev" + source: hosted + version: "2.0.3" + code_builder: + dependency: transitive + description: + name: code_builder + sha256: f692079e25e7869c14132d39f223f8eec9830eb76131925143b2129c4bb01b37 + url: "https://pub.dev" + source: hosted + version: "4.10.0" + collection: + dependency: transitive + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + convert: + dependency: transitive + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" + source: hosted + version: "3.1.1" + copy_with_extension: + dependency: transitive + description: + name: copy_with_extension + sha256: fbcf890b0c34aedf0894f91a11a579994b61b4e04080204656b582708b5b1125 + url: "https://pub.dev" + source: hosted + version: "5.0.4" + copy_with_extension_gen: + dependency: "direct main" + description: + name: copy_with_extension_gen + sha256: "51cd11094096d40824c8da629ca7f16f3b7cea5fc44132b679617483d43346b0" + url: "https://pub.dev" + source: hosted + version: "5.0.4" + crypto: + dependency: "direct main" + description: + name: crypto + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + url: "https://pub.dev" + source: hosted + version: "3.0.3" + dart_style: + dependency: transitive + description: + name: dart_style + sha256: "40ae61a5d43feea6d24bd22c0537a6629db858963b99b4bc1c3db80676f32368" + url: "https://pub.dev" + source: hosted + version: "2.3.4" + dio: + dependency: "direct main" + description: + name: dio + sha256: "49af28382aefc53562459104f64d16b9dfd1e8ef68c862d5af436cc8356ce5a8" + url: "https://pub.dev" + source: hosted + version: "5.4.1" + file: + dependency: transitive + description: + name: file + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + url: "https://pub.dev" + source: hosted + version: "7.0.0" + fixnum: + dependency: transitive + description: + name: fixnum + sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1" + url: "https://pub.dev" + source: hosted + version: "1.1.0" + frontend_server_client: + dependency: transitive + description: + name: frontend_server_client + sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612" + url: "https://pub.dev" + source: hosted + version: "3.2.0" + glob: + dependency: transitive + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + graphs: + dependency: transitive + description: + name: graphs + sha256: aedc5a15e78fc65a6e23bcd927f24c64dd995062bcd1ca6eda65a3cff92a4d19 + url: "https://pub.dev" + source: hosted + version: "2.3.1" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" + url: "https://pub.dev" + source: hosted + version: "3.2.1" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + io: + dependency: transitive + description: + name: io + sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" + json_annotation: + dependency: "direct main" + description: + name: json_annotation + sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467 + url: "https://pub.dev" + source: hosted + version: "4.8.1" + json_serializable: + dependency: "direct main" + description: + name: json_serializable + sha256: aa1f5a8912615733e0fdc7a02af03308933c93235bdc8d50d0b0c8a8ccb0b969 + url: "https://pub.dev" + source: hosted + version: "6.7.1" + logging: + dependency: transitive + description: + name: logging + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + matcher: + dependency: transitive + description: + name: matcher + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + meta: + dependency: transitive + description: + name: meta + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + url: "https://pub.dev" + source: hosted + version: "1.11.0" + mime: + dependency: transitive + description: + name: mime + sha256: "2e123074287cc9fd6c09de8336dae606d1ddb88d9ac47358826db698c176a1f2" + url: "https://pub.dev" + source: hosted + version: "1.0.5" + package_config: + dependency: transitive + description: + name: package_config + sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + path: + dependency: transitive + description: + name: path + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" + source: hosted + version: "1.9.0" + pool: + dependency: transitive + description: + name: pool + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" + source: hosted + version: "1.5.1" + pub_semver: + dependency: transitive + description: + name: pub_semver + sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + pubspec_parse: + dependency: transitive + description: + name: pubspec_parse + sha256: c63b2876e58e194e4b0828fcb080ad0e06d051cb607a6be51a9e084f47cb9367 + url: "https://pub.dev" + source: hosted + version: "1.2.3" + shelf: + dependency: transitive + description: + name: shelf + sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 + url: "https://pub.dev" + source: hosted + version: "1.4.1" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + source_gen: + dependency: transitive + description: + name: source_gen + sha256: "14658ba5f669685cd3d63701d01b31ea748310f7ab854e471962670abcf57832" + url: "https://pub.dev" + source: hosted + version: "1.5.0" + source_helper: + dependency: transitive + description: + name: source_helper + sha256: "6adebc0006c37dd63fe05bca0a929b99f06402fc95aa35bf36d67f5c06de01fd" + url: "https://pub.dev" + source: hosted + version: "1.3.4" + source_span: + dependency: transitive + description: + name: source_span + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" + source: hosted + version: "1.10.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" + source: hosted + version: "1.11.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" + source: hosted + version: "2.1.2" + stream_transform: + dependency: transitive + description: + name: stream_transform + sha256: "14a00e794c7c11aa145a170587321aedce29769c08d7f58b1d141da75e3b1c6f" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test_api: + dependency: transitive + description: + name: test_api + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + url: "https://pub.dev" + source: hosted + version: "0.6.1" + timing: + dependency: transitive + description: + name: timing + sha256: "70a3b636575d4163c477e6de42f247a23b315ae20e86442bebe32d3cabf61c32" + url: "https://pub.dev" + source: hosted + version: "1.0.1" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" + version: + dependency: "direct main" + description: + name: version + sha256: "3d4140128e6ea10d83da32fef2fa4003fccbf6852217bb854845802f04191f94" + url: "https://pub.dev" + source: hosted + version: "3.0.2" + watcher: + dependency: transitive + description: + name: watcher + sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" + url: "https://pub.dev" + source: hosted + version: "1.1.0" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b + url: "https://pub.dev" + source: hosted + version: "2.4.0" + yaml: + dependency: transitive + description: + name: yaml + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" + url: "https://pub.dev" + source: hosted + version: "3.1.2" +sdks: + dart: ">=3.2.3 <4.0.0" diff --git a/mnemo_cards_common/pubspec.yaml b/mnemo_cards_common/pubspec.yaml new file mode 100644 index 0000000..b15c695 --- /dev/null +++ b/mnemo_cards_common/pubspec.yaml @@ -0,0 +1,19 @@ +name: mnemo_cards_common +description: "A new Flutter package project." +version: 0.0.1 +homepage: none + +environment: + sdk: '>=3.2.3 <4.0.0' + +dependencies: + dio: ^5.3.3 + copy_with_extension_gen: ^5.0.4 + json_serializable: + json_annotation: ^4.7.0 + crypto: ^3.0.3 + version: ^3.0.2 + +dev_dependencies: + build_runner: + diff --git a/mnemo_cards_common_backend b/mnemo_cards_common_backend deleted file mode 160000 index f13478a..0000000 --- a/mnemo_cards_common_backend +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f13478ac9d074007804e003d38fdfcc663f33fe9