/*
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
package com.runicgateway.app.di

import com.runicgateway.app.core.auth.BuildDeviceNameProvider
import com.runicgateway.app.core.auth.DeviceNameProvider
import com.runicgateway.app.core.auth.EncryptedTokenStore
import com.runicgateway.app.core.auth.EncryptedTrustTokenStore
import com.runicgateway.app.core.auth.TokenStore
import com.runicgateway.app.core.auth.TrustTokenStore
import com.runicgateway.app.core.auth.sso.EncryptedPendingSsoStore
import com.runicgateway.app.core.auth.sso.PendingSsoStore
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

/** Binds the at-rest stores to their EncryptedSharedPreferences impls (§4.3). */
@Module
@InstallIn(SingletonComponent::class)
abstract class StorageModule {

    @Binds
    @Singleton
    abstract fun bindTokenStore(impl: EncryptedTokenStore): TokenStore

    @Binds
    @Singleton
    abstract fun bindPendingSsoStore(impl: EncryptedPendingSsoStore): PendingSsoStore

    /** The trusted-device token store — its own encrypted file, outlives session teardown. */
    @Binds
    @Singleton
    abstract fun bindTrustTokenStore(impl: EncryptedTrustTokenStore): TrustTokenStore

    @Binds
    @Singleton
    abstract fun bindDeviceNameProvider(impl: BuildDeviceNameProvider): DeviceNameProvider
}
