"""Migration metadata tests."""
from pathlib import Path

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


EXPECTED_TABLES = {
    "sports_centers",
    "branches",
    "sports",
    "membership_types",
    "memberships",
    "coaches",
    "sports_roles",
    "sports_permissions",
    "facilities",
    "courts",
    "rooms",
    "locker_rooms",
    "lockers",
    "device_providers",
    "devices",
    "attendance_gateways",
    "sports_configurations",
    "sports_events",
    "sports_settings",
    "sports_audit_logs",
    "members",
    "family_members",
    "emergency_contacts",
    "medical_information",
    "membership_cards",
    "digital_memberships",
    "waivers",
    "member_documents",
}


def test_alembic_revision_exists():
    root = Path(__file__).resolve().parents[2]
    rev = root / "alembic" / "versions" / "0003_phase_92_member_management.py"
    assert rev.exists()
    text = rev.read_text(encoding="utf-8")
    assert 'revision = "0003_phase_92_member_management"' in text
    assert "0002_phase_91_membership_catalog" in text


def test_expected_tables_in_metadata():
    assert EXPECTED_TABLES.issubset(set(Base.metadata.tables.keys()))
    assert "member_id" in Base.metadata.tables["memberships"].columns
