WatchNotificationRouter.swift 1 KB
//
//  WatchNotificationRouter.swift
//  Runner Watch App
//
//  Created by 权海 on 2026/6/17.
//

import Foundation
import Combine

final class WatchNotificationRouter: ObservableObject {

    static let shared = WatchNotificationRouter()

    @Published var pendingNotification: WatchNotificationPayload?

    private init() {}

    func handle(userInfo: [AnyHashable: Any]) {
        let payload = WatchNotificationPayload(userInfo: userInfo)
        DispatchQueue.main.async {
            self.pendingNotification = payload
        }
    }

    func consumeCachedPayloadIfNeeded() {
//        pendingNotification = WatchNotificationPayload(
//            id: id,
//            type: type
//        )
    }
}

struct WatchNotificationPayload {
    let id: String?
    let type: String?

    init(userInfo: [AnyHashable: Any]) {
        self.id = userInfo["id"] as? String
        self.type = userInfo["type"] as? String
    }

    init(id: String?, type: String?) {
        self.id = id
        self.type = type
    }
}