package com.github.nullptroma.wallenc.app.di.modules.data

import android.content.Context
import com.github.nullptroma.wallenc.infrastructure.android.db.RoomFactory
import com.github.nullptroma.wallenc.infrastructure.android.db.app.IAppDb
import com.github.nullptroma.wallenc.infrastructure.android.db.app.dao.StorageKeyMapDao
import com.github.nullptroma.wallenc.infrastructure.android.db.app.dao.StorageMetaInfoDao
import com.github.nullptroma.wallenc.infrastructure.android.db.app.dao.StorageSyncGroupDao
import com.github.nullptroma.wallenc.infrastructure.android.db.app.dao.YandexAccountDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

/** Room types are implemented in `:infrastructure-android` with `domain.vault` packages. */
@Module
@InstallIn(SingletonComponent::class)
object RoomModule {
    @Provides
    @Singleton
    fun provideRoomFactory(@ApplicationContext appContext: Context): RoomFactory {
        return RoomFactory(appContext)
    }

    @Provides
    @Singleton
    fun provideStorageKeyDao(database: IAppDb): StorageKeyMapDao {
        return database.storageKeyMapDao
    }

    @Provides
    @Singleton
    fun provideStorageMetaInfoDao(database: IAppDb): StorageMetaInfoDao {
        return database.storageMetaInfoDao
    }

    @Provides
    @Singleton
    fun provideStorageSyncGroupDao(database: IAppDb): StorageSyncGroupDao {
        return database.storageSyncGroupDao
    }

    @Provides
    @Singleton
    fun provideYandexAccountDao(database: IAppDb): YandexAccountDao {
        return database.yandexAccountDao
    }

    @Provides
    @Singleton
    fun provideAppDb(factory: RoomFactory): IAppDb {
        return factory.buildAppDb()
    }
}