package pt.whatsms.gateway.modules.settings

import androidx.preference.PreferenceManager
import pt.whatsms.gateway.helpers.SettingsHelper
import pt.whatsms.gateway.modules.encryption.EncryptionSettings
import pt.whatsms.gateway.modules.gateway.GatewaySettings
import pt.whatsms.gateway.modules.localserver.LocalServerSettings
import pt.whatsms.gateway.modules.logs.LogsSettings
import pt.whatsms.gateway.modules.messages.MessagesSettings
import pt.whatsms.gateway.modules.ping.PingSettings
import pt.whatsms.gateway.modules.receiver.StateStorage
import pt.whatsms.gateway.modules.webhooks.TemporaryStorage
import pt.whatsms.gateway.modules.webhooks.WebhooksSettings
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module


val settingsModule = module {
    singleOf(::SettingsService)
    factory { PreferenceManager.getDefaultSharedPreferences(get()) }
    factory { SettingsHelper(get()) }

    factory {
        EncryptionSettings(
            PreferencesStorage(get(), "encryption")
        )
    }
    factory {
        GatewaySettings(
            PreferencesStorage(get(), "gateway")
        )
    }
    factory {
        MessagesSettings(
            PreferencesStorage(get(), "messages")
        )
    }
    factory {
        LocalServerSettings(
            PreferencesStorage(get(), "localserver")
        )
    }
    factory {
        PingSettings(
            PreferencesStorage(get(), "ping")
        )
    }
    factory {
        LogsSettings(
            PreferencesStorage(get(), "logs")
        )
    }
    factory {
        WebhooksSettings(
            PreferencesStorage(get(), "webhooks")
        )
    }
    single {
        TemporaryStorage(
            PreferencesStorage(get(), "webhooks")
        )
    }
    single {
        StateStorage(
            PreferencesStorage(get(), "receiver")
        )
    }
}