from __future__ import annotations

from typing import Any

from pydantic import BaseModel, Field


class DHSToolCallRecord(BaseModel):
    """Bản ghi lệnh gọi công cụ thực tế (Ground Truth Tool Call) của AI Persona."""

    tool_name: str
    tool_input: dict[str, Any] = Field(default_factory=dict)
    tool_output: dict[str, Any] = Field(default_factory=dict)
    execution_time_ms: float = 0.0
    status: str = "SUCCESS"


class DHSMissionStep(BaseModel):
    """Bước thực thi trong quy trình phối hợp Multi-Agent của DeepSeek Harness."""

    step_index: int
    agent_code: str
    agent_name: str
    role_title: str
    model_used: str
    reasoning_summary: str
    tool_calls: list[DHSToolCallRecord] = Field(default_factory=list)
    step_output: dict[str, Any] = Field(default_factory=dict)
    status: str = "COMPLETED"
    execution_seconds: float = 0.0


class DHSMissionRequest(BaseModel):
    """Yêu cầu thực thi nhiệm vụ Agentic tự trị từ Ban Giám đốc."""

    mission_title: str = Field(..., description="Tiêu đề nhiệm vụ")
    mission_prompt: str = Field(
        ..., description="Nội dung chỉ đạo chi tiết của Ban Giám đốc"
    )
    target_project_id: str | None = Field(
        None, description="ID dự án mục tiêu (nếu có)"
    )
    pillar: str = Field(
        "xay_lap",
        description="Trụ cột nghiệp vụ (xay_lap, van_tai_xe_ben, cho_thue_ca_may, vat_tu_san_lap)",
    )
    deep_reasoning_enabled: bool = Field(
        True,
        description="Bật chế độ suy luận chuỗi tư duy CoT (DeepSeek R1 / Stealth OX)",
    )


class DHSMissionResponse(BaseModel):
    """Kết quả hoàn thành nhiệm vụ Agentic tự trị của DeepSeek Harness."""

    mission_id: str
    mission_title: str
    pillar: str
    orchestrator_model: str
    total_steps: int
    total_execution_seconds: float
    participating_agents: list[str]
    steps: list[DHSMissionStep]
    self_reflection_summary: dict[str, Any]
    executive_report: str
    artifacts: list[dict[str, Any]] = Field(default_factory=list)
    status: str = "COMPLETED"
    created_at: str


class DHSSampleMissionItem(BaseModel):
    """Kịch bản nhiệm vụ mẫu thực tế của DSCons."""

    sample_id: str
    title: str
    pillar: str
    pillar_title: str
    description: str
    target_partner: str
    suggested_prompt: str
    involved_personas: list[str]
