fluffychat/lib/pangea/activity_planner/activity_plan_request.dart
Kelrap 711ae38f4a
Model key cleanup (#4983)
* refactor: Group redundant ModelKey entries

* Add python script to find and replace hardcoded ModelKey values

* Edited Python script to not automatically use ModelKey for files not
already using it

* refactor: Ran script and accepted obvious changes

* rename 'duration' model key

---------

Co-authored-by: ggurdin <ggurdin@gmail.com>
2025-12-31 09:26:06 -05:00

97 lines
3.3 KiB
Dart

import 'package:fluffychat/pangea/activity_generator/media_enum.dart';
import 'package:fluffychat/pangea/common/constants/model_keys.dart';
import 'package:fluffychat/pangea/learning_settings/language_level_type_enum.dart';
class ActivityPlanRequest {
final String topic;
final String mode;
final String objective;
final String location;
final MediaEnum media;
LanguageLevelTypeEnum cefrLevel;
final String languageOfInstructions;
final String targetLanguage;
final int count;
int numberOfParticipants;
ActivityPlanRequest({
required this.topic,
required this.mode,
required this.objective,
required this.media,
required this.cefrLevel,
required this.languageOfInstructions,
required this.targetLanguage,
this.location = "any",
this.count = 3,
required this.numberOfParticipants,
});
Map<String, dynamic> toJson() {
return {
ModelKey.activityRequestTopic: topic,
ModelKey.mode: mode,
ModelKey.activityRequestObjective: objective,
ModelKey.activityRequestMedia: media.string,
ModelKey.activityRequestCefrLevel: cefrLevel.string,
ModelKey.activityRequestLanguageOfInstructions: languageOfInstructions,
ModelKey.targetLanguage: targetLanguage,
ModelKey.activityRequestCount: count,
ModelKey.activityRequestNumberOfParticipants: numberOfParticipants,
ModelKey.activityPlanLocation: location,
};
}
factory ActivityPlanRequest.fromJson(Map<String, dynamic> json) =>
ActivityPlanRequest(
topic: json[ModelKey.activityRequestTopic],
mode: json[ModelKey.mode],
objective: json[ModelKey.activityRequestObjective],
media: MediaEnum.nan.fromString(json[ModelKey.activityRequestMedia]),
cefrLevel: json[ModelKey.activityRequestCefrLevel] != null
? LanguageLevelTypeEnum.fromString(
json[ModelKey.activityRequestCefrLevel],
)
: LanguageLevelTypeEnum.a1,
languageOfInstructions:
json[ModelKey.activityRequestLanguageOfInstructions],
targetLanguage: json[ModelKey.targetLanguage],
count: json[ModelKey.activityRequestCount],
numberOfParticipants:
json[ModelKey.activityRequestNumberOfParticipants],
location: json[ModelKey.activityPlanLocation] ?? "any",
);
String get storageKey =>
'$topic-$mode-$objective-${media.string}-$cefrLevel-$languageOfInstructions-$targetLanguage-$numberOfParticipants';
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is ActivityPlanRequest &&
other.topic == topic &&
other.mode == mode &&
other.objective == objective &&
other.media == media &&
other.cefrLevel == cefrLevel &&
other.languageOfInstructions == languageOfInstructions &&
other.targetLanguage == targetLanguage &&
other.location == location &&
other.count == count &&
other.numberOfParticipants == numberOfParticipants;
}
@override
int get hashCode =>
topic.hashCode ^
mode.hashCode ^
objective.hashCode ^
media.hashCode ^
cefrLevel.hashCode ^
languageOfInstructions.hashCode ^
targetLanguage.hashCode ^
count.hashCode ^
location.hashCode ^
numberOfParticipants.hashCode;
}