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

import com.github.nullptroma.wallenc.app.di.modules.app.IoDispatcher
import com.github.nullptroma.wallenc.domain.vault.network.yandexdisk.YandexDiskApiFactory
import com.github.nullptroma.wallenc.domain.vault.network.yandexdisk.repository.YandexDiskRepositoryFactory
import com.github.nullptroma.wallenc.domain.vault.network.yandexuserinfo.YandexUserInfoApi
import com.github.nullptroma.wallenc.domain.vault.network.yandexuserinfo.YandexUserInfoApiFactory
import com.github.nullptroma.wallenc.domain.vault.network.yandexuserinfo.repository.YandexUserInfoRepository
import com.github.nullptroma.wallenc.domain.vault.ports.YandexAccountStore
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object NetworkModule {

    @Provides
    @Singleton
    fun provideYandexUserInfoApi(): YandexUserInfoApi = YandexUserInfoApiFactory.create()

    @Provides
    @Singleton
    fun provideYandexDiskApiFactory(
        yandexAccountStore: YandexAccountStore,
        @IoDispatcher ioDispatcher: CoroutineDispatcher,
    ): YandexDiskApiFactory = YandexDiskApiFactory(
        accountRepository = yandexAccountStore,
        ioDispatcher = ioDispatcher,
    )

    @Provides
    @Singleton
    fun provideYandexDiskRepositoryFactory(
        apiFactory: YandexDiskApiFactory,
        @IoDispatcher ioDispatcher: CoroutineDispatcher,
    ): YandexDiskRepositoryFactory = YandexDiskRepositoryFactory(
        apiFactory = apiFactory,
        ioDispatcher = ioDispatcher,
    )

    @Provides
    @Singleton
    fun provideYandexUserInfoRepository(
        api: YandexUserInfoApi,
        @IoDispatcher ioDispatcher: CoroutineDispatcher,
    ): YandexUserInfoRepository = YandexUserInfoRepository(api, ioDispatcher)
}
