package wang.yaojia.webterm.push

import dagger.BindsOptionalOf
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent

/**
 * The A31 seam. [FcmService.onNewToken] forwards a rotated FCM registration token here; the
 * implementation (A31 `PushRegistrar` — `POST /push/fcm-token` per host) is NOT part of A30.
 *
 * A30 only DECLARES this interface and consumes it optionally, so the FCM client compiles and runs
 * standalone before A31 lands. A31 supplies the behaviour with a single `@Binds PushTokenSink`.
 */
public interface PushTokenSink {
    /** A new/rotated device token is available — (re)register it with every paired host (A31). */
    public fun onTokenRefreshed(token: String)
}

/**
 * Makes `Optional<PushTokenSink>` injectable even when NOTHING binds a [PushTokenSink] yet (A31 not
 * landed) — Hilt injects `Optional.empty()`. Once A31 adds `@Binds PushTokenSink`, the same injection
 * point sees the real sink. This is the clean "optional collaborator" pattern (no mutable global).
 */
@Module
@InstallIn(SingletonComponent::class)
public interface PushSeamModule {
    @BindsOptionalOf
    public fun optionalPushTokenSink(): PushTokenSink
}
