Files
workoutsplus/WorkoutsPlus/Features/WorkoutSession/WorkoutSession.swift
2024-10-28 12:00:56 +01:00

104 lines
2.3 KiB
Swift

//
// WorkoutSession.swift
// WorkoutsPlus
//
// Created by Felix Förtsch on 07.09.24.
//
import Foundation
import SwiftData
@Model
final class WorkoutSession: Nameable {
var id = UUID()
var name: String
// TODO: Think about if a refrence to the workout makes sense; a Workout could change.
// var workout: Workout
var workoutSessionItems: [WorkoutSessionItem] = []
init(start workout: Workout) {
self.name = workout.name
for workoutItem in workout.getWorkoutItems() {
workoutSessionItems.append(WorkoutSessionItem(workoutSession: self, planned: workoutItem))
}
}
// State
var isPaused = false
// var isCancelled: Bool
// var isDeleted: Bool
// var isSynced: Bool
// My workout session started at:
var startDate: Date = Date.now
// My workout session was completed at:
var stopDate: Date? = nil
// My workout session took me x seconds.
var workoutDuration: TimeInterval = 0.0
var pauseDuration: TimeInterval = 0.0
// My workout session is completed and moved to the workout log.
var isCompleted = false
// Exercise Progress
var currentExercise = 0
func isActive() -> Bool {
return stopDate == nil
}
// MARK: -- Workout Controls
// func pause() {
// isPaused = true
// }
//
// func resume() {
// isPaused = false
// }
// Call stop() to terminate the workout.
func stop() {
isCompleted = true
stopDate = Date.now
// duration = stopDate!.timeIntervalSince(startDate)
}
func prevExercise() {
if currentExercise > 0 {
currentExercise -= 1
}
}
func nextExercise() {
}
// MARK: -- Workout Information
func getFormattedDuration() -> String {
let elapsedTime = Date.now.timeIntervalSince(startDate)
let formatter = DateComponentsFormatter()
formatter.allowedUnits = [.hour, .minute, .second]
formatter.unitsStyle = .positional
return formatter.string(from: elapsedTime) ?? "00:00:00"
}
func getTotalExerciseCount() -> Double {
return 100.0
}
func getCurrentExerciseIndex() -> Double {
return Double(currentExercise)
}
func getCurrentTodo() -> String {
return getCurrentExerciseMetric() + " " + getCurrentExerciseName()
}
func getCurrentExerciseName() -> String {
return "Hello"
}
func getCurrentExerciseMetric() -> String {
return "Hello"
}
}