package com.ffii.fpsms.modules.common.alert

import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.reactive.function.client.WebClient

@Configuration
@EnableConfigurationProperties(SchedulerSyncAlertProperties::class)
open class SmsAlertConfig(
    private val properties: SchedulerSyncAlertProperties,
    private val webClientBuilder: WebClient.Builder,
) {
    @Bean
    open fun smsSender(): SmsSender {
        val sms = properties.sms
        val useTwilio =
            sms.enabled &&
                (sms.provider.equals("twilio", ignoreCase = true) ||
                    (sms.accountSid.isNotBlank() && sms.authToken.isNotBlank()))
        return if (useTwilio) {
            TwilioSmsSender(properties, webClientBuilder)
        } else {
            LoggingSmsSender()
        }
    }
}
