//
// WatchAppDelegate.swift
// Workouts Watch App
//
// Copyright 2025 Rouslan Zenetl. All Rights Reserved.
//

import SwiftUI
import WatchKit
import HealthKit

/// Bridges watchOS lifecycle into the workout session. When the phone starts a workout
/// it calls `startWatchApp(toHandle:)`; watchOS launches (or foregrounds) this app and
/// delivers the configuration to `handle(_:)`, where we start a session to claim
/// foreground runtime. The session manager is shared with the view tree via the
/// environment (see `WorkoutsWatchApp`).
@MainActor
final class WatchAppDelegate: NSObject, WKApplicationDelegate {
    let sessionManager = WorkoutSessionManager()

    func applicationDidFinishLaunching() {
        sessionManager.requestAuthorization()
    }

    func handle(_ workoutConfiguration: HKWorkoutConfiguration) {
        sessionManager.start(with: workoutConfiguration)
    }
}
