//
//  TimerModule.swift
//  Werkout_ios
//
//  Created by Trey Tartt on 6/14/23.
//

import Foundation
import WatchConnectivity
import AVFoundation
import HealthKit

enum WatchActions: Codable {
    case nextExercise
    case restartExercise
    case previousExercise
    case stopWorkout
    case pauseWorkout
    case workoutComplete(Data)
}

enum PhoneToWatchActions: Codable {
    case inExercise(WatchPackageModel)
    case reset
    case endWorkout
    case startWorkout
}

class BridgeModule: NSObject, ObservableObject {
    private let kMessageKey = "message"

    static let shared = BridgeModule()
    @Published var isShowingOnExternalDisplay = false

    @Published var isInWorkout = false
    var completedWorkout: (() -> Void)?
    @Published var currentWorkoutRunTimeInSeconds: Int = -1
    var currentWorkoutRunTimer: Timer?
    
    public var workoutStartDate: Date?

    public var currentExerciseTimer: Timer?
    
    @Published public private(set) var currentExerciseInfo = CurrentWorkoutInfo()
    @Published var previewWorkout: Workout?
    
    @Published var currentExerciseTimeLeft: Int = 0
    
    private var isWatchConnected = false
    // workoutEndDate fills out WatchPackageModel.workoutEndDate which
    // tells the watch app to stop the workout
    public var workoutEndDate: Date?
    @Published var healthKitUUID: UUID?
    @Published var isPaused = false
    
    let session: WCSession = WCSession.default
}
