"""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 = {
    "venues",
    "branches",
    "dining_areas",
    "dining_tables",
    "menus",
    "menu_categories",
    "menu_items",
    "bundle_definitions",
    "tenant_bundles",
    "feature_toggles",
    "hospitality_roles",
    "hospitality_permissions",
    "hospitality_configurations",
    "hospitality_events",
    "hospitality_settings",
    "hospitality_audit_logs",
    "allergens",
    "modifier_groups",
    "modifier_options",
    "menu_item_modifiers",
    "menu_item_allergens",
    "availability_windows",
    "menu_media_refs",
    "menu_localizations",
    "qr_codes",
    "qr_menu_sessions",
    "qr_ordering_sessions",
    "carts",
    "cart_lines",
    "reservations",
    "table_assignments",
    "service_requests",
    "waitlist_entries",
    "pos_registers",
    "pos_shifts",
    "pos_tickets",
    "pos_ticket_lines",
    "pos_payments",
    "pos_discounts",
    "pos_tax_lines",
    "pos_floor_plans",
    "pos_stations",
    "kitchen_stations",
    "kitchen_tickets",
    "kitchen_ticket_items",
    "connector_registrations",
    "connector_dispatches",
    "analytics_report_definitions",
    "analytics_snapshots",
}


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


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