"""Smoke test for migration 0003: model classes import, schema shape correct."""

from backend.app.models import (
    Base,
    ImageRecord,
    MLSettings,
    TagAlias,
    TagSuggestionRejection,
)


def test_new_tables_registered():
    expected = {
        "tag_suggestion_rejection",
        "tag_alias",
        "ml_settings",
    }
    assert expected.issubset(Base.metadata.tables.keys())


def test_image_record_columns_renamed():
    cols = {c.name for c in ImageRecord.__table__.columns}
    # Legacy tagger columns are all gone: tagger_predictions/wd14_* dropped in
    # 0046, tagger_model_version + centroid_scores dropped in 0068 (#1199, Camie
    # retirement). The SigLIP embedding columns are the live ML fields.
    assert "siglip_embedding" in cols
    assert "siglip_model_version" in cols
    assert "tagger_model_version" not in cols
    assert "centroid_scores" not in cols
    assert "tagger_predictions" not in cols
    assert "wd14_predictions" not in cols


def test_tag_alias_composite_pk():
    pk_cols = {c.name for c in TagAlias.__table__.primary_key.columns}
    assert pk_cols == {"alias_string", "alias_category"}


def test_ml_settings_singleton_constraint():
    names = {c.name for c in MLSettings.__table__.constraints}
    assert "ck_ml_settings_singleton" in names


def test_tag_suggestion_rejection_pk():
    pk_cols = {c.name for c in TagSuggestionRejection.__table__.primary_key.columns}
    assert pk_cols == {"image_record_id", "tag_id"}
