"""
Meta-Agent Types

Core data structures for multi-persona reasoning.
"""

from dataclasses import dataclass, field
from enum import Enum
from typing import Dict, List, Optional


class DebateRole(Enum):
    """Role in internal debate."""

    ADVOCATE = "advocate"  # Argues in favor
    CRITIC = "critic"  # Devil's advocate
    MEDIATOR = "mediator"  # Seeks balance
    SYNTHESIZER = "synthesizer"  # Combines views


class ConsensusLevel(Enum):
    """Level of consensus reached."""

    FULL = "full"  # All agree
    MAJORITY = "majority"  # >50% agree
    PARTIAL = "partial"  # Some agreement
    NONE = "none"  # No consensus


@dataclass
class Perspective:
    """A perspective generated by a persona."""

    persona_name: str
    role: DebateRole
    content: str
    confidence: float = 0.8
    reasoning: str = ""
    metadata: Dict = field(default_factory=dict)

    @property
    def is_critical(self) -> bool:
        """Whether this is a critical perspective."""
        return self.role == DebateRole.CRITIC


@dataclass
class DebateRound:
    """Result of a single debate round."""

    round_number: int
    arguments: List[str] = field(default_factory=list)
    counterarguments: List[str] = field(default_factory=list)
    agreements: List[str] = field(default_factory=list)
    disagreements: List[str] = field(default_factory=list)

    @property
    def has_movement(self) -> bool:
        """Whether progress was made in this round."""
        return len(self.agreements) > 0 or len(self.counterarguments) > 0


@dataclass
class DebateResult:
    """Final result of internal debate."""

    rounds: List[DebateRound]
    consensus_level: ConsensusLevel
    key_points: List[str] = field(default_factory=list)
    unresolved_tensions: List[str] = field(default_factory=list)
    winning_perspective: Optional[str] = None

    @property
    def total_rounds(self) -> int:
        """Number of debate rounds."""
        return len(self.rounds)

    @property
    def reached_consensus(self) -> bool:
        """Whether meaningful consensus was reached."""
        return self.consensus_level in [ConsensusLevel.FULL, ConsensusLevel.MAJORITY]


@dataclass
class MetaAgentResponse:
    """Response from the multi-persona meta-agent."""

    final_answer: str
    perspectives: List[Perspective]
    debate_result: DebateResult
    synthesis_rationale: str = ""
    confidence: float = 0.8
    metadata: Dict = field(default_factory=dict)

    @property
    def perspective_count(self) -> int:
        """Number of perspectives considered."""
        return len(self.perspectives)
