from pathlib import Path
import unittest


ROOT = Path(__file__).resolve().parents[1]


class RepositoryLayoutTest(unittest.TestCase):
    def test_application_boundaries_are_explicit(self) -> None:
        for relative in (
            "vpd-backoffice/pom.xml",
            "vpd-backoffice/src/main",
            "ai-web-agent-console/app.py",
            "ai-web-agent-console/ai_web_agent_console",
            "dds-backoffice/pom.xml",
            "database/adb",
            "deploy/vpd-backoffice",
            "deploy/ai-web-agent-console",
        ):
            self.assertTrue((ROOT / relative).exists(), relative)

    def test_ambiguous_legacy_roots_are_absent(self) -> None:
        for relative in (
            "pom.xml",
            "src",
            "sql",
            "poc4_active_source_20260714",
        ):
            self.assertFalse((ROOT / relative).exists(), relative)

    def test_console_has_one_named_python_package(self) -> None:
        console = ROOT / "ai-web-agent-console"
        self.assertFalse((console / "src").exists())
        self.assertFalse((console / "apps").exists())
        self.assertTrue((console / "ai_web_agent_console" / "__init__.py").is_file())

        source = "\n".join(
            path.read_text(encoding="utf-8")
            for path in (console / "ai_web_agent_console").glob("*.py")
        )
        source += (console / "app.py").read_text(encoding="utf-8")
        for forbidden in (
            "from src.",
            "src.poc3",
            "src.poc4",
            "src.agent_console",
            "apps/poc4",
        ):
            self.assertNotIn(forbidden, source)

    def test_vpd_backoffice_packages_database_sql(self) -> None:
        pom = (ROOT / "vpd-backoffice" / "pom.xml").read_text(encoding="utf-8")
        self.assertIn("<directory>../database/adb</directory>", pom)
        self.assertNotIn("<directory>sql/adb</directory>", pom)


if __name__ == "__main__":
    unittest.main()
