"""Tests for the personality system."""

import pytest

from agent_scout.personality.personality import (
    Personality,
    PersonalityConfig,
    PersonalityPreset,
)


@pytest.fixture
def personality():
    return Personality()


def test_default_preset(personality):
    assert personality.preset == PersonalityPreset.FRIENDLY


def test_get_system_prompt_friendly(personality):
    prompt = personality.get_system_prompt()
    assert "friendly" in prompt.lower() or "enthusiastic" in prompt.lower()


def test_get_system_prompt_professional():
    p = Personality(PersonalityConfig(preset=PersonalityPreset.PROFESSIONAL))
    prompt = p.get_system_prompt()
    assert "professional" in prompt.lower()


def test_get_system_prompt_minimal():
    p = Personality(PersonalityConfig(preset=PersonalityPreset.MINIMAL))
    prompt = p.get_system_prompt()
    assert "brief" in prompt.lower()


def test_get_system_prompt_custom():
    p = Personality(
        PersonalityConfig(
            preset=PersonalityPreset.CUSTOM,
            custom_prompt="You are a pirate assistant. Arrr!",
        )
    )
    prompt = p.get_system_prompt()
    assert "pirate" in prompt.lower()


def test_custom_without_prompt_falls_back():
    p = Personality(PersonalityConfig(preset=PersonalityPreset.CUSTOM))
    prompt = p.get_system_prompt()
    # Falls back to professional
    assert "professional" in prompt.lower()


def test_format_message_friendly(personality):
    msg = personality.format_message("task_start", description="Find flights")
    assert "Find flights" in msg
    # Friendly should be conversational
    assert "on it" in msg.lower() or "let me" in msg.lower()


def test_format_message_professional():
    p = Personality(PersonalityConfig(preset=PersonalityPreset.PROFESSIONAL))
    msg = p.format_message("task_start", description="Find flights")
    assert "Find flights" in msg
    assert "initiating" in msg.lower()


def test_format_message_minimal():
    p = Personality(PersonalityConfig(preset=PersonalityPreset.MINIMAL))
    msg = p.format_message("task_start", description="Find flights")
    assert msg == "Find flights"


def test_format_message_custom_templates():
    config = PersonalityConfig(
        preset=PersonalityPreset.CUSTOM,
        custom_templates={"task_start": "Yo, working on {description}!"},
    )
    p = Personality(config)
    msg = p.format_message("task_start", description="Find flights")
    assert msg == "Yo, working on Find flights!"


def test_format_message_unknown_key(personality):
    msg = personality.format_message("nonexistent_key")
    assert msg == "nonexistent_key"


def test_set_preset(personality):
    personality.preset = PersonalityPreset.MINIMAL
    assert personality.preset == PersonalityPreset.MINIMAL


def test_available_presets(personality):
    presets = personality.available_presets()
    assert "professional" in presets
    assert "friendly" in presets
    assert "minimal" in presets
    assert "custom" in presets


def test_config_access(personality):
    config = personality.config
    assert config.preset == PersonalityPreset.FRIENDLY
