package app.closer.core.billing

import com.revenuecat.purchases.CustomerInfo
import kotlinx.coroutines.flow.Flow

/**
 * Reactive entitlement source of truth.
 *
 * Implementations observe server-side entitlement state from Firestore and
 * fall back to the local RevenueCat SDK state when no server document exists.
 * Callers must collect [isPremium] (or call it repeatedly) rather than caching
 * a one-time snapshot, because entitlement state changes when subscriptions
 * renew, expire, cancel, or transfer.
 */
interface EntitlementChecker {

    /**
     * Reactive stream that emits `true` whenever the current user has an
     * active premium entitlement. Emits `false` when signed out or when the
     * entitlement is expired / revoked.
     */
    fun isPremium(): Flow<Boolean>

    /**
     * One-shot check for the current premium status. Prefer [isPremium] for
     * UI that needs to react to subscription changes.
     */
    suspend fun hasPremium(): Boolean

    /**
     * Notify the checker of a RevenueCat [CustomerInfo] update so it can
     * fall back correctly when the server-side document is missing.
     */
    fun onCustomerInfoUpdated(customerInfo: CustomerInfo)
}
