import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/exercise_result.dart';
import 'package:aitrainer_app/model/result.dart';

enum ResultType { running, man, woman, none }

extension ResultTypeExt on ResultType {
  bool equals(ResultType type) => this.toString() == type.toString();
}

class ExerciseResultRepository {
  final List<ResultExt> _results = [];
  ResultType resultType;

  ExerciseResultRepository({required this.resultType}) {
    if (resultType.equals(ResultType.man) || resultType.equals(ResultType.woman)) {
      //_results.add(ResultExt(itemString: ResultItem.time.description));
      _results.add(ResultExt(itemString: ResultItem.reps_volume.description.toString()));
      _results.add(ResultExt(itemString: ResultItem.weight_volume.description.toString()));
      _results.add(ResultExt(itemString: ResultItem.bpm_max.description.toString()));
      _results.add(ResultExt(itemString: ResultItem.calorie.description.toString()));
      _results.add(ResultExt(itemString: ResultItem.bpm_avg.description.toString()));
      _results.add(ResultExt(itemString: ResultItem.fatburn_percent.description.toString()));
      _results.add(ResultExt(itemString: ResultItem.bpm_min.description.toString()));
    } else {
      //_results.add(ResultExt(itemString: ResultItem.time.description));
      _results.add(ResultExt(itemString: ResultItem.distance.description.toString()));
      _results.add(ResultExt(itemString: ResultItem.bpm_max.description.toString()));
      _results.add(ResultExt(itemString: ResultItem.calorie.description.toString()));
      _results.add(ResultExt(itemString: ResultItem.bpm_avg.description.toString()));
      _results.add(ResultExt(itemString: ResultItem.fatburn_percent.description.toString()));
      _results.add(ResultExt(itemString: ResultItem.bpm_min.description.toString()));
      _results.add(ResultExt(itemString: ResultItem.steps.description.toString()));
      _results.add(ResultExt(itemString: ResultItem.speed_max.description.toString()));
    }
  }

  List<ResultExt> getResults() => this._results;

  Future<void> saveExerciseResults() async {
    this._results.forEach((result) async {
      ExerciseResult exerciseResult = ExerciseResult();
      exerciseResult.customerId = Cache().userLoggedIn!.customerId!;
      exerciseResult.exerciseId = result.exerciseId!;
      exerciseResult.dateFrom = result.dateFrom!;
      exerciseResult.dateTo = result.dateTo;
      exerciseResult.resultType = result.itemString;
      exerciseResult.value = result.data;
      //await ExerciseResultApi().saveExerciseResult(exerciseResult);
    });
  }
}
