"""Performance / index validation — foundation hot paths are index-backed."""
from __future__ import annotations

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


def test_foundation_list_indexes_present():
    """Performance gate for Phase 7.0: tenant list/filter columns are indexed."""
    indexed = {
        (table.name, tuple(col.name for col in idx.columns))
        for table in Base.metadata.tables.values()
        for idx in table.indexes
    }
    required = {
        ("loyalty_programs", ("tenant_id", "status")),
        ("loyalty_programs", ("tenant_id",)),
        ("members", ("tenant_id", "status")),
        ("members", ("tenant_id", "tier_id")),
        ("members", ("tenant_id", "membership_expires_at")),
        ("membership_lifecycle_events", ("tenant_id", "member_id")),
        ("point_accounts", ("tenant_id", "program_id")),
        ("rewards", ("tenant_id", "status")),
        ("campaigns", ("tenant_id", "status")),
        ("outbox_events", ("status",)),
    }
    for item in required:
        assert item in indexed, f"missing index covering {item}"
