"""
Tests for augmentation presets module.

TDD Phase 4: RED - Write tests first, then implement to pass.
"""

import pytest


class TestPresets:
    """Tests for augmentation presets."""

    def test_presets_dict_exists(self) -> None:
        """Test that PRESETS dictionary exists."""
        from shared.augmentation.presets import PRESETS

        assert isinstance(PRESETS, dict)
        assert len(PRESETS) > 0

    def test_expected_presets_exist(self) -> None:
        """Test that expected presets are defined."""
        from shared.augmentation.presets import PRESETS

        expected_presets = ["conservative", "moderate", "aggressive", "scanned_document"]

        for preset_name in expected_presets:
            assert preset_name in PRESETS, f"Missing preset: {preset_name}"

    def test_preset_structure(self) -> None:
        """Test that each preset has required structure."""
        from shared.augmentation.presets import PRESETS

        for name, preset in PRESETS.items():
            assert "description" in preset, f"Preset {name} missing description"
            assert "config" in preset, f"Preset {name} missing config"
            assert isinstance(preset["description"], str)
            assert isinstance(preset["config"], dict)

    def test_get_preset_config(self) -> None:
        """Test getting config from preset."""
        from shared.augmentation.presets import get_preset_config

        config = get_preset_config("conservative")

        assert config is not None
        # Should have at least some augmentations defined
        assert len(config) > 0

    def test_get_preset_config_unknown_raises(self) -> None:
        """Test that getting unknown preset raises error."""
        from shared.augmentation.presets import get_preset_config

        with pytest.raises(ValueError, match="Unknown preset"):
            get_preset_config("nonexistent_preset")

    def test_create_config_from_preset(self) -> None:
        """Test creating AugmentationConfig from preset."""
        from shared.augmentation.config import AugmentationConfig
        from shared.augmentation.presets import create_config_from_preset

        config = create_config_from_preset("moderate")

        assert isinstance(config, AugmentationConfig)

    def test_conservative_preset_is_safe(self) -> None:
        """Test that conservative preset only enables safe augmentations."""
        from shared.augmentation.presets import create_config_from_preset

        config = create_config_from_preset("conservative")

        # Should NOT enable geometric transforms
        assert config.perspective_warp.enabled is False

        # Should NOT enable heavy degradation
        assert config.wrinkle.enabled is False
        assert config.edge_damage.enabled is False
        assert config.stain.enabled is False

    def test_aggressive_preset_enables_more(self) -> None:
        """Test that aggressive preset enables more augmentations."""
        from shared.augmentation.presets import create_config_from_preset

        config = create_config_from_preset("aggressive")

        enabled = config.get_enabled_augmentations()

        # Should enable multiple augmentation types
        assert len(enabled) >= 6

    def test_list_presets(self) -> None:
        """Test listing available presets."""
        from shared.augmentation.presets import list_presets

        presets = list_presets()

        assert isinstance(presets, list)
        assert len(presets) >= 4

        # Each item should have name and description
        for preset in presets:
            assert "name" in preset
            assert "description" in preset
