import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/training_plan.dart';
import 'package:aitrainer_app/util/app_language.dart';

class TrainingPlanDayRepository {
  const TrainingPlanDayRepository();

  void assignTrainingPlanDays() {
    List<TrainingPlan>? plans = Cache().getTrainingPlans();
    if (plans == null) {
      return;
    }
    plans.forEach((plan) {
      if (plan.details != null) {
        plan.details!.forEach((element) {
          element.day = this.getNameById(element.dayId);
        });
      }
    });
  }

  String? getNameById(int? dayId) {
    if (dayId == null) {
      return "";
    }
    String? name;
    for (var day in Cache().getTrainingPlanDays()) {
      if (day.dayId == dayId) {
        name = day.nameTranslations[AppLanguage().appLocal.languageCode];
        break;
      }
    }
    return name;
  }
}
