"""
T-UC4: Sprach-Deployment — Spanish (es).

Verifies that the i18n system is ready for the live demo:
- Admin languages page is reachable
- Spanish is available as a choice but NOT pre-installed
- xx base set exists with entries
"""

import pytest


class TestI18nReadiness:

    def test_xxBaseSetExists(self, db):
        """The xx (meta/base) language set must exist with entries."""
        try:
            from modules.datamodels.datamodelUiLanguage import UiLanguageSet
            sets = db.getRecordset(UiLanguageSet, recordFilter={"id": "xx"})
            assert sets, "xx base set not found — run i18n sync first"
            entries = sets[0].get("entries") or []
            assert len(entries) > 50, f"xx set has only {len(entries)} entries — expected 50+"
        except Exception as e:
            pytest.skip(f"i18n table not accessible: {e}")

    def test_spanishNotPreInstalled(self, db):
        """Spanish (es) must NOT be pre-installed — it will be created live."""
        try:
            from modules.datamodels.datamodelUiLanguage import UiLanguageSet
            sets = db.getRecordset(UiLanguageSet, recordFilter={"id": "es"})
            assert len(sets) == 0, "Spanish (es) is already installed — remove it before demo!"
        except Exception as e:
            pytest.skip(f"i18n table not accessible: {e}")

    def test_germanSetExists(self, db):
        """German (de) set must exist and be complete."""
        try:
            from modules.datamodels.datamodelUiLanguage import UiLanguageSet
            sets = db.getRecordset(UiLanguageSet, recordFilter={"id": "de"})
            assert sets, "German (de) set not found"
        except Exception as e:
            pytest.skip(f"i18n table not accessible: {e}")

    def test_englishSetExists(self, db):
        """English (en) set must exist."""
        try:
            from modules.datamodels.datamodelUiLanguage import UiLanguageSet
            sets = db.getRecordset(UiLanguageSet, recordFilter={"id": "en"})
            assert sets, "English (en) set not found"
        except Exception as e:
            pytest.skip(f"i18n table not accessible: {e}")
