147 lines
4.7 KiB
Dart
147 lines
4.7 KiB
Dart
import 'package:aitrainer_app/model/cache.dart';
|
|
import 'package:aitrainer_app/model/exercise.dart';
|
|
import 'package:aitrainer_app/model/exercise_plan_detail.dart';
|
|
import 'package:aitrainer_app/model/exercise_type.dart';
|
|
import 'package:aitrainer_app/repository/training_plan_day_repository.dart';
|
|
|
|
class CustomerTrainingPlanDetails {
|
|
/// customerTrainingPlanDetails
|
|
int? customerTrainingPlanDetailsId;
|
|
|
|
/// trainingPlanDetailsId
|
|
int? trainingPlanDetailsId;
|
|
|
|
/// exerciseTypeId
|
|
int? exerciseTypeId;
|
|
|
|
/// set
|
|
int? set;
|
|
|
|
/// repeats
|
|
int? repeats;
|
|
|
|
/// weight
|
|
double? weight;
|
|
|
|
int? restingTime;
|
|
bool? parallel;
|
|
String? day;
|
|
|
|
int? dayId;
|
|
|
|
/// exerciseType
|
|
ExerciseType? exerciseType;
|
|
|
|
ExercisePlanDetailState state = ExercisePlanDetailState.start;
|
|
|
|
List<Exercise> exercises = [];
|
|
|
|
bool isTest = false;
|
|
|
|
CustomerTrainingPlanDetails();
|
|
|
|
CustomerTrainingPlanDetails.fromJson(Map json) {
|
|
this.customerTrainingPlanDetailsId = json['customerTrainingPlanDetailsId'];
|
|
this.exerciseTypeId = json['exerciseTypeId'];
|
|
this.set = json['set'];
|
|
this.repeats = json['repeats'];
|
|
this.weight = json['weight'];
|
|
this.restingTime = json['restingTime'];
|
|
this.parallel = json['parallel'];
|
|
this.day = json['day'];
|
|
}
|
|
|
|
CustomerTrainingPlanDetails.fromJsonWithExerciseList(Map json) {
|
|
this.customerTrainingPlanDetailsId = json['customerTrainingPlanDetailsId'] == "null" || json['customerTrainingPlanDetailsId'] == null
|
|
? 0
|
|
: json['customerTrainingPlanDetailsId'];
|
|
this.trainingPlanDetailsId = json['trainingPlanDetailsId'];
|
|
this.exerciseTypeId = json['exerciseTypeId'];
|
|
this.set = json['set'];
|
|
this.repeats = json['repeats'] == "null" ? -1 : json['repeats'];
|
|
this.weight = json['weight'];
|
|
this.restingTime = json['restingTime'];
|
|
this.parallel = json['parallel'] == "false"
|
|
? false
|
|
: json['parallel'] == "true"
|
|
? true
|
|
: null;
|
|
this.dayId = json['dayId'] == "null" ? null : json['dayId'];
|
|
TrainingPlanDayRepository trainingPlanDayRepository = TrainingPlanDayRepository();
|
|
this.day = trainingPlanDayRepository.getNameById(this.dayId);
|
|
|
|
try {
|
|
Iterable iterable = json['exercises'];
|
|
this.exercises = iterable.map((exercise) => Exercise.fromJson(exercise)).toList();
|
|
} on Exception catch (e) {
|
|
print("JsonDecode error " + e.toString());
|
|
}
|
|
|
|
if (json['state'] == ExercisePlanDetailState.finished.toStr()) {
|
|
this.state = ExercisePlanDetailState.finished;
|
|
} else if (json['state'] == ExercisePlanDetailState.inProgress.toStr()) {
|
|
this.state = ExercisePlanDetailState.inProgress;
|
|
} else if (json['state'] == ExercisePlanDetailState.skipped.toStr()) {
|
|
this.state = ExercisePlanDetailState.skipped;
|
|
} else {
|
|
this.state = ExercisePlanDetailState.start;
|
|
}
|
|
this.isTest = json['isTest'] == "true" ? true : false;
|
|
|
|
this.exerciseType = Cache().getExerciseTypeById(exerciseTypeId!);
|
|
}
|
|
|
|
ExerciseType? getExerciseType() => exerciseType;
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
"customerTrainingPlanDetailsId": this.customerTrainingPlanDetailsId,
|
|
"exerciseTypeId": this.exerciseTypeId,
|
|
"set": this.set,
|
|
"repeats": this.repeats,
|
|
"weight": this.weight,
|
|
"restingTime": this.restingTime,
|
|
"parallel": this.parallel,
|
|
"day": this.day == null ? '1.' : this.day,
|
|
};
|
|
|
|
Map<String, dynamic> toJsonWithExercises() {
|
|
final Map<String, dynamic> jsonMap = {
|
|
"customerTrainingPlanDetailsId": this.customerTrainingPlanDetailsId,
|
|
"trainingPlanDetailsId": this.trainingPlanDetailsId,
|
|
"exerciseTypeId": this.exerciseTypeId,
|
|
"set": this.set,
|
|
"repeats": this.repeats,
|
|
"weight": this.weight,
|
|
"restingTime": this.restingTime,
|
|
"parallel": this.parallel,
|
|
'exercises': exercises.isEmpty ? [].toString() : exercises.map((exercise) => exercise.toJson()).toList().toString(),
|
|
'state': this.state.toStr(),
|
|
"isTest": this.isTest,
|
|
"dayId": this.dayId,
|
|
};
|
|
|
|
//print("Detail toJson $jsonMap");
|
|
return jsonMap;
|
|
}
|
|
|
|
@override
|
|
String toString() => this.toJsonWithExercises().toString();
|
|
|
|
void copy(CustomerTrainingPlanDetails from) {
|
|
this.customerTrainingPlanDetailsId = from.customerTrainingPlanDetailsId;
|
|
this.trainingPlanDetailsId = from.trainingPlanDetailsId;
|
|
this.exerciseTypeId = from.exerciseTypeId;
|
|
this.exerciseType = from.exerciseType;
|
|
this.set = from.set;
|
|
this.repeats = from.repeats;
|
|
this.weight = from.weight;
|
|
this.restingTime = from.restingTime;
|
|
this.parallel = from.parallel;
|
|
this.exercises = from.exercises;
|
|
this.state = from.state;
|
|
this.isTest = from.isTest;
|
|
this.day = from.day;
|
|
this.dayId = from.dayId;
|
|
}
|
|
}
|