from enum import Enum

from pydantic import BaseModel, Field


class PermissionClass(str, Enum):
    READ = "read"
    WRITE = "write"
    EXTERNAL = "external"


class SideEffectScope(str, Enum):
    NONE = "none"
    LOCAL_STATE = "local_state"
    DB_WRITE = "db_write"
    NETWORK = "network"


class AgentManifest(BaseModel):
    agent_id: str
    display_name: str
    role_value: str
    system_prompt_key: str
    routing_hints: list[str]
    default_sub_commanders: list[str]
    can_spawn_children: bool = False
    allowed_spawn_role_values: list[str] = Field(default_factory=list)
    skill_context_key: str | None = None
    continuity_policy: str | None = None
    clarification_policy: str | None = None


class SubCommanderManifest(BaseModel):
    sub_commander_id: str
    parent_agent_id: str
    prompt_text: str
    capability_ids: list[str]


class CapabilityManifest(BaseModel):
    capability_id: str
    tool_name: str
    permission_class: PermissionClass = PermissionClass.READ
    side_effect_scope: SideEffectScope = SideEffectScope.NONE
    supports_retry: bool = False
    idempotent: bool = False
    safe_for_parallel_use: bool = False
    requires_confirmation: bool = False


class SpecialistTemplateManifest(BaseModel):
    template_id: str
    display_name: str
    description: str
    allowed_capability_ids: list[str] | None = None
