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

import android.content.Context
import com.github.nullptroma.wallenc.ui.resources.UiStringResolver
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 UiStringModule {

    @Provides
    @Singleton
    fun provideUiStringResolver(@ApplicationContext context: Context): UiStringResolver =
        object : UiStringResolver {
            override fun invoke(id: Int, vararg formatArgs: Any): String =
                if (formatArgs.isEmpty()) {
                    context.getString(id)
                } else {
                    context.getString(id, *formatArgs)
                }

            override fun plurals(id: Int, quantity: Int, vararg formatArgs: Any): String =
                if (formatArgs.isEmpty()) {
                    context.resources.getQuantityString(id, quantity)
                } else {
                    context.resources.getQuantityString(id, quantity, *formatArgs)
                }
        }
}
