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

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


EXPECTED_TABLES = {
    "clinics",
    "branches",
    "departments",
    "doctors",
    "patients",
    "healthcare_roles",
    "healthcare_permissions",
    "external_provider_configs",
    "healthcare_configurations",
    "healthcare_settings",
    "healthcare_audit_logs",
    "outbox_events",
    "schedules",
    "availability_windows",
    "appointment_types",
    "appointments",
    "waiting_list_entries",
    "visit_sessions",
    "visit_notes",
    "clinic_services",
    "staff_assignments",
    "clinic_policies",
    "operating_hours_policies",
    "patient_portal_profiles",
    "patient_document_refs",
    "patient_notification_preferences",
    "medical_records",
    "encounters",
    "conditions",
    "allergies",
    "medication_statements",
    "immunization_records",
    "medical_record_access_logs",
    "pharmacies",
    "prescription_orders",
    "prescription_lines",
    "prescription_status_history",
    "delivery_integration_registrations",
    "delivery_job_intents",
    "delivery_job_status_snapshots",
}


def test_alembic_head_revision():
    versions = Path(__file__).resolve().parents[2] / "alembic" / "versions"
    files = list(versions.glob("0008_phase_137*.py"))
    assert files, "missing 0008_phase_137 migration"


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