import 'ExercisePrescription.dart';

class SessionTemplate {
  String? id;

  String programId;

  /// 0-based day within the training week.
  int dayIndex;

  String name;

  /// True when this session loads the lower body hard enough to require the
  /// program recovery gap before the next one.
  bool highIntensityLowerBody;

  List<ExercisePrescription> prescriptions;

  SessionTemplate({
    this.id,
    this.programId = "",
    this.dayIndex = 0,
    this.name = "",
    this.highIntensityLowerBody = false,
    List<ExercisePrescription>? prescriptions,
  }) : prescriptions = prescriptions ?? <ExercisePrescription>[];

  factory SessionTemplate.fromJson(Map<String, dynamic> json) {
    return SessionTemplate(
      id: json['id'],
      programId: json['programId'] ?? "",
      dayIndex: json['dayIndex'] ?? 0,
      name: json['name'] ?? "",
      highIntensityLowerBody: json['highIntensityLowerBody'] ?? false,
      prescriptions: json['prescriptions'] == null
          ? <ExercisePrescription>[]
          : (json['prescriptions'] as List)
              .map((item) => ExercisePrescription.fromJson(item))
              .toList(),
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['programId'] = programId;
    data['dayIndex'] = dayIndex;
    data['name'] = name;
    data['highIntensityLowerBody'] = highIntensityLowerBody;
    data['prescriptions'] = prescriptions.map((item) => item.toJson()).toList();
    return data;
  }
}
