"""Migration / metadata validation."""
from pathlib import Path

from alembic.config import Config
from alembic.script import ScriptDirectory

from app.core.database import Base
import app.models  # noqa: F401


EXPECTED_TABLES = {
    "experience_workspaces",
    "experience_locale_profiles",
    "experience_roles",
    "experience_permissions",
    "external_provider_configs",
    "render_engine_registrations",
    "experience_configurations",
    "experience_settings",
    "experience_audit_logs",
    "experience_sites",
    "experience_pages",
    "experience_site_domains",
    "experience_components",
    "experience_component_versions",
    "experience_page_component_placements",
    "experience_themes",
    "experience_theme_versions",
    "experience_layouts",
    "experience_layout_versions",
    "experience_site_theme_bindings",
    "experience_page_layout_bindings",
    "experience_templates",
    "experience_template_versions",
    "experience_template_instantiations",
    "experience_site_locale_bindings",
    "experience_localizations",
    "experience_media_refs",
    "experience_forms",
    "experience_form_submissions",
    "experience_surveys",
    "experience_survey_responses",
    "experience_appointment_pages",
    "experience_appointment_booking_refs",
    "experience_publish_releases",
    "experience_domain_edge_bindings",
    "experience_seo_metadata",
    "experience_sitemap_shells",
    "experience_robots_shells",
    "experience_pwa_manifests",
    "experience_bundle_definitions",
    "experience_tenant_bundles",
    "experience_license_bindings",
    "experience_feature_toggles",
    "experience_consumer_connector_registrations",
    "experience_consumer_connector_dispatches",
    "experience_widget_definitions",
    "experience_widget_instances",
    "experience_notify_dispatches",
    "experience_analytics_report_definitions",
    "experience_analytics_snapshots",
    "experience_ai_content_hook_registrations",
    "experience_ai_content_dispatches",
}


def test_alembic_head_is_phase_1110():
    root = Path(__file__).resolve().parents[2]
    cfg = Config(str(root / "alembic.ini"))
    script = ScriptDirectory.from_config(cfg)
    assert script.get_current_head() == "0011_phase_1110_analytics"


def test_metadata_contains_foundation_tables():
    names = set(Base.metadata.tables.keys())
    assert EXPECTED_TABLES.issubset(names)
