package de.softwareapp_hb.privateqrscanner.i18n

import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test

class AppLocaleCatalogTest {
    @Test
    fun parseReadsSelectableAndPlannedLocaleRows() {
        val options = AppLocaleCatalog.parse(
            """
            # comment
            tag	resourceQualifier	status	nativeName	coverage
            system	system	system	System default	Device language
            en	values	complete	English	Default
            de	values-de	complete	Deutsch	Germany
            es	values-es	planned	Español	Spain
            """.trimIndent()
        )

        assertEquals(4, options.size)
        assertNull(options[0].languageTag)
        assertEquals(AppLocaleStatus.System, options[0].status)
        assertEquals("de", options[2].languageTag)
        assertEquals(AppLocaleStatus.Planned, options[3].status)
    }

    @Test
    fun resolveOptionFallsBackToSystemDefaultForUnknownTag() {
        val systemDefault = AppLocaleOption(
            storageTag = AppLocaleCatalog.SYSTEM_STORAGE_TAG,
            languageTag = null,
            status = AppLocaleStatus.System,
            displayName = "System default"
        )
        val english = AppLocaleOption(
            storageTag = "en",
            languageTag = "en",
            status = AppLocaleStatus.Complete,
            displayName = "English"
        )

        val resolved = AppLocaleCatalog.resolveOption(listOf(systemDefault, english), "fr")

        assertEquals(AppLocaleCatalog.SYSTEM_STORAGE_TAG, resolved.storageTag)
    }
}
