"""Tests for analysis/config.py SVD_THEMES structure."""

import pytest


def test_svd_themes_has_required_fields():
    """Each SVD_THEMES entry must have label, explanation, positive_pole, negative_pole, flip."""
    from analysis.config import SVD_THEMES

    required_fields = {"label", "explanation", "positive_pole", "negative_pole", "flip"}

    for comp_id, theme in SVD_THEMES.items():
        missing = required_fields - set(theme.keys())
        assert not missing, f"Component {comp_id} missing fields: {missing}"


def test_svd_themes_no_left_right_pole():
    """SVD_THEMES should NOT have left_pole or right_pole (derived at runtime)."""
    from analysis.config import SVD_THEMES

    for comp_id, theme in SVD_THEMES.items():
        assert "left_pole" not in theme, f"Component {comp_id} has deprecated left_pole"
        assert "right_pole" not in theme, (
            f"Component {comp_id} has deprecated right_pole"
        )


def test_svd_themes_flip_is_boolean():
    """Each SVD_THEMES flip field must be a boolean."""
    from analysis.config import SVD_THEMES

    for comp_id, theme in SVD_THEMES.items():
        assert isinstance(theme.get("flip"), bool), (
            f"Component {comp_id} flip is not boolean"
        )


def test_svd_themes_poles_are_strings():
    """Each SVD_THEMES pole field must be a non-empty string."""
    from analysis.config import SVD_THEMES

    for comp_id, theme in SVD_THEMES.items():
        pos = theme.get("positive_pole", "")
        neg = theme.get("negative_pole", "")
        assert isinstance(pos, str) and len(pos) > 0, (
            f"Component {comp_id} has invalid positive_pole"
        )
        assert isinstance(neg, str) and len(neg) > 0, (
            f"Component {comp_id} has invalid negative_pole"
        )
