"""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",
    "staff_certificates",
    "staff_skills",
    "staff_working_hours",
    "staff_availability",
    "staff_assignments",
    "equipment",
    "sports_sessions",
    "bookings",
    "waiting_list_entries",
    "resource_reservations",
    "attendance_records",
    "access_logs",
    "training_programs",
    "exercises",
    "workout_plans",
    "workout_assignments",
    "training_goals",
    "measurements",
    "progress_records",
    "nutrition_plans",
    "assessments",
    "performance_records",
    "body_compositions",
    "competitions",
    "competition_teams",
    "competition_groups",
    "competition_registrations",
    "competition_matches",
    "competition_results",
    "competition_rankings",
    "competition_medals",
    "competition_judges",
    "competition_certificates",
}


def test_alembic_revision_exists():
    root = Path(__file__).resolve().parents[2]
    rev = root / "alembic" / "versions" / "0008_phase_97_competitions.py"
    assert rev.exists()
    text = rev.read_text(encoding="utf-8")
    assert 'revision = "0008_phase_97_competitions"' in text
    assert "0007_phase_96_training" 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
