from typing import List, Dict, Any, Optional, Literal
from pydantic import BaseModel, Field
from enum import Enum

class IntelligenceTier(str, Enum):
    SOTA = "SOTA"       # State of the Art (e.g., GPT-4o, Claude 3.5 Sonnet)
    ADVANCED = "Advanced" # High-Performance/Cost-Efficient (e.g., GPT-4o-mini)
    BASIC = "Basic"     # Fast/Cheap (e.g., Llama 3 8B)

# --- Intent Classification Schemas ---

class IntentClassification(BaseModel):
    """
    Represents the classified intent of a user's request.
    """
    intent_type: Literal["debate", "review", "tool_use", "chat"] = Field(
        ..., 
        description="The primary category of the user's request."
    )
    confidence_score: float = Field(
        ..., 
        ge=0.0, le=1.0, 
        description="The confidence level of the classification."
    )
    reasoning: str = Field(
        ..., 
        description="Brief explanation of why this intent was chosen."
    )
    suggested_tier: Optional[IntelligenceTier] = Field(
        None, 
        description="The recommended Intelligence Tier for handling this request."
    )

# --- Execution Plan Schemas ---

class Step(BaseModel):
    """
    A single step in an execution plan.
    """
    id: str = Field(..., description="Unique identifier for the step (e.g., 'step_1').")
    description: str = Field(..., description="Human-readable description of what this step does.")
    tool_name: Optional[str] = Field(None, description="The name of the tool to execute, if any.")
    tool_args: List[str] = Field(default_factory=list, description="Arguments to pass to the tool.")
    dependencies: List[str] = Field(default_factory=list, description="IDs of steps that must complete before this one.")

class ExecutionPlan(BaseModel):
    """
    A structured plan generated by the Dynamic Planner to fulfill a user request.
    """
    intent: str = Field(..., description="The intent that triggered this plan.")
    dependencies: List[str] = Field(default_factory=list, description="IDs of steps that must complete before this one.")

class ExecutionPlan(BaseModel):
    """
    A structured plan generated by the Dynamic Planner to fulfill a user request.
    """
    intent: str = Field(..., description="The intent that triggered this plan.")
    steps: List[Step] = Field(..., description="Ordered list of steps to execute.")

# --- Workflow Pipeline Schemas ---

class WorkflowStep(BaseModel):
    """
    A single step definition in a YAML workflow.
    """
    name: str = Field(..., description="Unique name of the step")
    action: str = Field(..., description="Action type (e.g., 'run_tool', 'ask_user', 'llm_generate')")
    args: Dict[str, Any] = Field(default_factory=dict, description="Arguments for the action")
    timeout: int = Field(300, description="Timeout in seconds")
    retry_on_failure: bool = Field(True, description="Whether to retry on failure")
    max_retries: int = Field(3, description="Maximum number of retries")
    dependencies: List[str] = Field(default_factory=list, description="List of step names that must complete first")
    on_success: Optional[Dict[str, Any]] = Field(None, description="Next step logic on success")
    on_failure: Optional[Dict[str, Any]] = Field(None, description="Fallback logic on failure")

class WorkflowDefinition(BaseModel):
    """
    Complete definition of a workflow pipeline.
    """
    name: str
    description: Optional[str] = ""
    version: str = "1.0"
    steps: List[WorkflowStep]

