"""Tests for summarization parsing utilities."""

from __future__ import annotations

import logging

import pytest

from noteflow.infrastructure.summarization._parsing import build_style_prompt


class TestBuildStylePrompt:
    """Tests for build_style_prompt function."""

    @pytest.mark.parametrize(
        ("tone", "expected_fragment"),
        [
            ("professional", "formal, business-appropriate"),
            ("casual", "conversational, approachable"),
            ("technical", "precise technical terminology"),
            ("friendly", "warm, personable"),
        ],
    )
    def test_tone_produces_expected_instruction(
        self,
        tone: str,
        expected_fragment: str,
    ) -> None:
        """Each tone value produces its corresponding instruction."""
        result = build_style_prompt(tone=tone)

        assert expected_fragment in result, f"Tone '{tone}' should produce fragment '{expected_fragment}'"

    @pytest.mark.parametrize(
        ("format_style", "expected_fragment"),
        [
            ("bullet_points", "bullet points"),
            ("narrative", "flowing paragraphs"),
            ("structured", "headers and organized"),
            ("concise", "extremely brief"),
        ],
    )
    def test_format_produces_expected_instruction(
        self,
        format_style: str,
        expected_fragment: str,
    ) -> None:
        """Each format value produces its corresponding instruction."""
        result = build_style_prompt(format_style=format_style)

        assert expected_fragment in result, f"Format '{format_style}' should produce fragment '{expected_fragment}'"

    @pytest.mark.parametrize(
        ("verbosity", "expected_fragment"),
        [
            ("minimal", "only essential"),
            ("balanced", "moderate detail"),
            ("detailed", "comprehensive information"),
            ("comprehensive", "all relevant details"),
        ],
    )
    def test_verbosity_produces_expected_instruction(
        self,
        verbosity: str,
        expected_fragment: str,
    ) -> None:
        """Each verbosity value produces its corresponding instruction."""
        result = build_style_prompt(verbosity=verbosity)

        assert expected_fragment in result, f"Verbosity '{verbosity}' should produce fragment '{expected_fragment}'"

    def test_combines_all_options(self) -> None:
        """All three options combine into single prompt."""
        result = build_style_prompt(
            tone="professional",
            format_style="bullet_points",
            verbosity="detailed",
        )

        assert "formal" in result, "Professional tone should include 'formal'"
        assert "bullet points" in result, "Bullet points format should include 'bullet points'"
        assert "comprehensive" in result, "Detailed verbosity should include 'comprehensive'"

    def test_no_options_returns_empty_string(self) -> None:
        """No options produces empty string."""
        result = build_style_prompt()

        assert result == "", "No options should produce empty string"

    def test_none_values_returns_empty_string(self) -> None:
        """Explicit None values produce empty string."""
        result = build_style_prompt(tone=None, format_style=None, verbosity=None)

        assert result == "", "Explicit None values should produce empty string"

    def test_unknown_tone_ignored(self, caplog: pytest.LogCaptureFixture) -> None:
        """Unknown tone value is ignored with debug log."""
        with caplog.at_level(logging.DEBUG):
            result = build_style_prompt(tone="unknown_tone")

        assert result == "", "Unknown tone should produce empty string"
        assert "Unknown tone value ignored" in caplog.text, "Debug log should mention unknown tone"

    def test_unknown_format_ignored(self, caplog: pytest.LogCaptureFixture) -> None:
        """Unknown format value is ignored with debug log."""
        with caplog.at_level(logging.DEBUG):
            result = build_style_prompt(format_style="unknown_format")

        assert result == "", "Unknown format should produce empty string"
        assert "Unknown format value ignored" in caplog.text, "Debug log should mention unknown format"

    def test_unknown_verbosity_ignored(self, caplog: pytest.LogCaptureFixture) -> None:
        """Unknown verbosity value is ignored with debug log."""
        with caplog.at_level(logging.DEBUG):
            result = build_style_prompt(verbosity="unknown_verbosity")

        assert result == "", "Unknown verbosity should produce empty string"
        assert "Unknown verbosity value ignored" in caplog.text, "Debug log should mention unknown verbosity"

    def test_partial_valid_options(self) -> None:
        """Valid options used even when some are invalid."""
        result = build_style_prompt(
            tone="professional",
            format_style="invalid",
            verbosity="minimal",
        )

        assert "formal" in result, "Valid professional tone should be included"
        assert "essential" in result, "Valid minimal verbosity should be included"
        assert "invalid" not in result, "Invalid format value should not appear in result"

    def test_empty_string_values_treated_as_none(self) -> None:
        """Empty string values produce empty result (falsy check)."""
        result = build_style_prompt(tone="", format_style="", verbosity="")

        assert result == "", "Empty string values should produce empty result"
