from __future__ import annotations

from sqlalchemy import create_engine, inspect
from sqlalchemy.pool import StaticPool

import app.models  # noqa: F401 - import all model modules before reading metadata
from app.db.session import Base


def test_fresh_sqlite_schema_matches_model_metadata():
    engine = create_engine(
        "sqlite:///:memory:",
        connect_args={"check_same_thread": False},
        poolclass=StaticPool,
    )

    Base.metadata.create_all(bind=engine)
    inspector = inspect(engine)

    actual_tables = set(inspector.get_table_names())
    expected_tables = set(Base.metadata.tables)
    assert actual_tables == expected_tables

    for table_name, table in Base.metadata.tables.items():
        actual_columns = {column["name"] for column in inspector.get_columns(table_name)}
        expected_columns = {column.name for column in table.columns}
        assert actual_columns == expected_columns
