//
//  AppDelegate.swift
//  LeCountdown
//
//  Created by Laurent Morvillier on 24/01/2023.
//

import Foundation
import UIKit

class AppDelegate : NSObject, UIApplicationDelegate {
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        
        UNUserNotificationCenter.current().delegate = self
        Conductor.maestro.cleanup()
        return true
    }
        
}

extension AppDelegate: UNUserNotificationCenterDelegate {
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async {

        print("didReceive notification")

        Conductor.maestro.stopSoundIfPossible()
    }
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        print("willPresent notification")
        completionHandler([.banner])
        
        Conductor.maestro.notifyUser(countdownId: notification.request.identifier)
    }
    
}
