/*
 * Copyright (C) 2017/2021 e-voyageurs technologies
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ai.tock.bot.engine

import ai.tock.bot.connector.ConnectorType
import ai.tock.bot.connector.ConnectorType.Companion.none
import ai.tock.shared.defaultLocale
import ai.tock.translator.I18nLabelValue
import ai.tock.translator.UserInterfaceType
import ai.tock.translator.defaultUserInterface
import ai.tock.translator.raw
import io.mockk.every
import io.mockk.spyk
import java.util.Locale
import kotlin.test.Test
import kotlin.test.assertEquals

class I18nTranslatorTest {

    private class Impl : I18nTranslator {
        override val userLocale: Locale get() = defaultLocale
        override val userInterfaceType: UserInterfaceType get() = defaultUserInterface
        override val sourceConnectorType: ConnectorType get() = none
        override val targetConnectorType: ConnectorType get() = none
        override val contextId: String? get() = null

        override fun i18n(defaultLabel: CharSequence, args: List<Any?>): I18nLabelValue =
            I18nLabelValue(defaultLabel.toString(), "namespace", "category", defaultLabel, args)
    }

    @Test
    fun `translate with list args call translate with varargs`() {
        val impl = spyk(Impl())

        every { impl.translate("text", "a", "b") } returns "ok".raw

        val result = impl.translate("text", listOf("a", "b"))

        assertEquals("ok".raw, result)
    }
}
