package com.diegocayo.organizame.data.di

import android.content.Context
import com.diegocayo.organizame.data.local.datasource.PreferencesDataSource
import com.diegocayo.organizame.data.local.datasource.PreferencesDataSourceImpl
import com.diegocayo.organizame.data.repository.LoginRepositoryImpl
import com.diegocayo.organizame.data.repository.UserRepositoryImpl
import com.diegocayo.organizame.domain.repository.LoginRepository
import com.diegocayo.organizame.domain.repository.UserRepository
import com.diegocayo.organizame.utils.moshi.MoshiParser
import com.squareup.moshi.Moshi
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

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

    @Provides
    @Singleton
    fun providePreferencesDataSource(
        context: Context,
        moshiParser: MoshiParser
    ): PreferencesDataSource {
        return PreferencesDataSourceImpl(context, moshiParser)
    }

    @Provides
    @Singleton
    internal fun provideMoshi(): Moshi {
        return Moshi.Builder().build()
    }

    @Provides
    @Singleton
    internal fun provideMoshiParser(moshi: Moshi): MoshiParser {
        return MoshiParser(moshi)
    }

    @Provides
    @Singleton
    fun provideUserRepository(
        preferencesDataSource: PreferencesDataSource
    ): UserRepository {
        return UserRepositoryImpl(preferencesDataSource)
    }

    @Provides
    @Singleton
    fun provideLoginRepository(
        preferencesDataSource: PreferencesDataSource
    ): LoginRepository {
        return LoginRepositoryImpl(preferencesDataSource)
    }

    @Provides
    @Singleton
    fun provideContext(@ApplicationContext context: Context): Context {
        return context
    }
} 