//
//  PaymentPushEventCenter.swift
//  suixinkan
//
//  Created by Codex on 2026/6/29.
//

import Combine
import Foundation

/// 收款推送事件，对齐 Android PushBus 在收款页内的分发语义。
struct PaymentPushEvent: Equatable, Sendable {
    let type: Int
    let dataJSON: String?
}

@MainActor
/// 收款推送事件中心，供 PushNotificationManager 发布、收款页订阅。
final class PaymentPushEventCenter {
    static let shared = PaymentPushEventCenter()

    private let subject = PassthroughSubject<PaymentPushEvent, Never>()

    private init() {}

    /// 收款页可订阅的推送事件流。
    var events: AnyPublisher<PaymentPushEvent, Never> {
        subject.eraseToAnyPublisher()
    }

    /// 发布一条收款相关推送事件。
    func post(type: Int, dataJSON: String?) {
        subject.send(PaymentPushEvent(type: type, dataJSON: dataJSON))
    }
}
