//
//  SodaLiveApp.swift
//  SodaLive
//
//  Created by klaus on 2023/08/09.
//

import SwiftUI

import FBSDKCoreKit
import AppsFlyerLib

@main
struct SodaLiveApp: App {
    
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    
    @ObservedObject var viewModel = AppViewModel()
    
    var body: some Scene {
        WindowGroup {
            ContentView()
                .onReceive(NotificationCenter.default.publisher(for: UIApplication.didEnterBackgroundNotification)) { _ in
                    CreatorCommunityMediaPlayerManager.shared.pauseContent()
                }
                .onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)) { _ in
                    UIApplication.shared.applicationIconBadgeNumber = 0
                    
                    AppsFlyerLib.shared().start()
                    viewModel.fetchAndUpdateIdfa()
                    viewModel.getMemberInfo()
                }
                .onOpenURL { url in
                    DEBUG_LOG("I have received a URL through a custom scheme! \(url.absoluteString)")
                    ApplicationDelegate.shared.application(UIApplication.shared, open: url, options: [:])
                    AppsFlyerLib.shared().handleOpen(url)
                }
        }
    }
}