"""Migration 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 = {
    "beauty_organizations",
    "beauty_branches",
    "beauty_roles",
    "beauty_permissions",
    "external_provider_configs",
    "booking_engine_registrations",
    "beauty_configurations",
    "beauty_settings",
    "beauty_audit_logs",
    "staff_schedules",
    "staff_availabilities",
    "schedule_exceptions",
    "appointment_types",
    "appointments",
    "appointment_status_history",
    "waiting_list_entries",
    "treatment_rooms",
    "stations",
    "branch_operating_hours",
    "branch_policies",
    "service_categories",
    "beauty_services",
    "service_variants",
    "branch_service_assignments",
    "service_media_refs",
    "customer_profiles",
    "customer_preferences",
    "visit_history_entries",
    "customer_document_refs",
    "package_definitions",
    "package_lines",
    "customer_packages",
    "package_redemptions",
    "membership_plans",
    "customer_memberships",
    "membership_lifecycle_events",
    "staff_profiles",
    "staff_skills",
    "staff_certificates",
    "commission_rules",
    "commission_entries",
    "marketing_campaign_refs",
    "loyalty_integration_configs",
    "communication_integration_configs",
    "integration_dispatches",
    "outbox_events",
}


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


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