from datetime import datetime
from pydantic import BaseModel
from typing import Optional


class SkillCreate(BaseModel):
    name: str
    description: Optional[str] = None
    instructions: str
    agent_type: str  # master/schedule_planner/executor/librarian/analyst
    tools: list[str] = []
    required_context: list[str] = []
    output_format: Optional[str] = None
    visibility: str = "private"
    team_id: Optional[str] = None
    is_active: bool = True
    status: str = "active"
    scope: list[str] = []
    effectiveness: Optional[float] = None
    review_after: Optional[datetime] = None


class SkillUpdate(BaseModel):
    # All fields Optional
    name: Optional[str] = None
    description: Optional[str] = None
    instructions: Optional[str] = None
    agent_type: Optional[str] = None
    tools: Optional[list[str]] = None
    required_context: Optional[list[str]] = None
    output_format: Optional[str] = None
    visibility: Optional[str] = None
    team_id: Optional[str] = None
    is_active: Optional[bool] = None
    status: Optional[str] = None
    scope: Optional[list[str]] = None
    effectiveness: Optional[float] = None
    review_after: Optional[datetime] = None


class SkillOut(BaseModel):
    id: str
    name: str
    description: Optional[str]
    instructions: str
    agent_type: str
    tools: list[str]
    required_context: list[str]
    output_format: Optional[str]
    visibility: str
    is_builtin: bool
    team_id: Optional[str]
    is_active: bool
    status: str
    scope: list[str]
    effectiveness: Optional[float]
    review_after: Optional[datetime]
    activation_count: int
    last_activated_at: Optional[datetime]
    owner_id: str
    created_at: datetime
    updated_at: datetime

    model_config = {"from_attributes": True}
