import 'package:fluffychat/pangea/choreographer/choreo_constants.dart'; import 'package:fluffychat/pangea/choreographer/it/completed_it_step_model.dart'; import 'package:fluffychat/pangea/choreographer/it/gold_route_tracker_model.dart'; import 'package:fluffychat/pangea/choreographer/it/it_response_model.dart'; class ITStepModel { late List continuances; late bool isFinal; ITStepModel({this.continuances = const [], this.isFinal = false}); factory ITStepModel.fromResponse({ required String sourceText, required String currentText, required ITResponseModel responseModel, required List? storedGoldContinuances, }) { final List gold = storedGoldContinuances ?? responseModel.goldContinuances ?? []; final goldTracker = GoldRouteTrackerModel(gold, sourceText); final isFinal = responseModel.isFinal; List continuances; if (responseModel.continuances.isEmpty) { continuances = []; } else { final ContinuanceModel? goldCont = goldTracker.currentContinuance( currentText: currentText, sourceText: sourceText, ); if (goldCont != null) { continuances = [ ...responseModel.continuances .where((c) => c.text.toLowerCase() != goldCont.text.toLowerCase()) .map((e) { //we only want one green choice and for that to be our gold if (e.level == ChoreoConstants.levelThresholdForGreen) { return e.copyWith( level: ChoreoConstants.levelThresholdForYellow, ); } return e; }), goldCont, ]; continuances.shuffle(); } else { continuances = List.from(responseModel.continuances); } } return ITStepModel( continuances: continuances, isFinal: isFinal, ); } ITStepModel copyWith({ List? continuances, bool? isFinal, }) { return ITStepModel( continuances: continuances ?? this.continuances, isFinal: isFinal ?? this.isFinal, ); } }