//
//  WatchDelegate.swift
//  Werkout_watch Watch App
//
//  Created by Trey Tartt on 7/1/24.
//

import WatchKit
import HealthKit

class WatchDelegate: NSObject, WKApplicationDelegate {
    func applicationDidFinishLaunching() {
        autorizeHealthKit()
    }
    
    func applicationDidBecomeActive() {
        
    }
    
    func applicationWillResignActive() {
        
    }
    
    func handle(_ workoutConfiguration: HKWorkoutConfiguration) {
//        WatchWorkout.shared.startWorkout()
    }
    
    func autorizeHealthKit() {
        let healthKitTypes: Set = [
            HKObjectType.quantityType(forIdentifier: .heartRate)!,
            HKObjectType.quantityType(forIdentifier: .activeEnergyBurned)!,
            HKObjectType.quantityType(forIdentifier: .oxygenSaturation)!,
            HKObjectType.activitySummaryType(),
            HKQuantityType.workoutType()
        ]
        HKHealthStore().requestAuthorization(toShare: nil, read: healthKitTypes) { (succ, error) in
            if !succ {
                fatalError("Error requesting authorization from health store: \(String(describing: error)))")
            }
        }
    }
}
