@file:Suppress("HardCodedStringLiteral")

package eu.gaudian.translator.model.grammar

import eu.gaudian.translator.model.grammar.LocalDictionaryMorphologyMapper.parseMorphology
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import org.junit.Assert.assertEquals
import org.junit.Test

class LocalDictionaryMorphologyMapperTest {

    @Test
    fun testGermanNounDeclensionParsing() {
        // Test JSON from the issue description
        val json = """
        {
            "senses": [
                {
                    "glosses": ["Stille, Einsamkeit im Wald"],
                    "raw_tags": ["als religiöses und literarisches Motiv"],
                    "examples": [
                        "„Der schöne Kranz gefiel wohl Allen,",
                        "„Zum gottgefälligen Büßerleben zogen sich Eremiten, Klausner und Inklusen in die Waldeinsamkeit zurück und lebten dort in Höhlen oder Hütten, vom Volk mit schaudernder Ehrfurcht bestaunt.“"
                    ],
                    "sense_index": "1"
                }
            ],
            "phonetics": {
                "ipa": ["[ˈvaltˌʔaɪ̯nzaːmkaɪ̯t]"]
            },
            "hyphenation": ["Wald", "ein", "sam", "keit"],
            "forms": [
                {
                    "form": "Waldeseinsamkeit",
                    "tags": ["variant"]
                },
                {
                    "form": "die Waldeinsamkeit",
                    "tags": ["nominative", "singular"]
                },
                {
                    "form": "die Waldeinsamkeiten",
                    "tags": ["nominative", "plural"]
                },
                {
                    "form": "der Waldeinsamkeit",
                    "tags": ["genitive", "singular"]
                },
                {
                    "form": "der Waldeinsamkeiten",
                    "tags": ["genitive", "plural"]
                },
                {
                    "form": "der Waldeinsamkeit",
                    "tags": ["dative", "singular"]
                },
                {
                    "form": "den Waldeinsamkeiten",
                    "tags": ["dative", "plural"]
                },
                {
                    "form": "die Waldeinsamkeit",
                    "tags": ["accusative", "singular"]
                },
                {
                    "form": "die Waldeinsamkeiten",
                    "tags": ["accusative", "plural"]
                }
            ],
            "grammatical_features": {
                "tags": ["feminine"],
                "gender": "feminine"
            }
        }
        """.trimIndent()

        val data = Json.decodeFromString<JsonObject>(json)
        val result = parseMorphology(
            langCode = "de",
            pos = "noun",
            lemma = "Waldeinsamkeit",
            data = data,
            languageConfig = null
        )

        // Verify that we get a Noun morphology with declension
        assert(result is WordMorphology.Noun) { "Expected Noun morphology, got ${result?.javaClass?.simpleName}" }
        
        val noun = result as WordMorphology.Noun
        val declension = noun.declension
        
        // Verify we have all four cases
        assertEquals(listOf("nominative", "genitive", "dative", "accusative"), declension.cases)
        assertEquals(listOf("singular", "plural"), declension.numbers)
        
        // Verify we have forms for all case/number combinations
        assertEquals(8, declension.forms.size) // 4 cases × 2 numbers = 8 forms
        
        // Verify specific forms
        assertEquals("die Waldeinsamkeit", declension.forms["nominative" to "singular"])
        assertEquals("die Waldeinsamkeiten", declension.forms["nominative" to "plural"])
        assertEquals("der Waldeinsamkeit", declension.forms["genitive" to "singular"])
        assertEquals("der Waldeinsamkeiten", declension.forms["genitive" to "plural"])
        assertEquals("der Waldeinsamkeit", declension.forms["dative" to "singular"])
        assertEquals("den Waldeinsamkeiten", declension.forms["dative" to "plural"])
        assertEquals("die Waldeinsamkeit", declension.forms["accusative" to "singular"])
        assertEquals("die Waldeinsamkeiten", declension.forms["accusative" to "plural"])
    }
}