"""Pydantic schemas for Technique endpoints."""

import uuid
from datetime import datetime

from pydantic import BaseModel, ConfigDict

from app.models.enums import TechniqueStatus


# ── Create ──────────────────────────────────────────────────────────

class TechniqueCreate(BaseModel):
    """Payload for creating a new technique."""

    mitre_id: str
    name: str
    description: str | None = None
    tactic: str | None = None
    platforms: list[str] | None = None


# ── Update ──────────────────────────────────────────────────────────

class TechniqueUpdate(BaseModel):
    """Payload for partially updating an existing technique.
    Every field is optional so callers send only what changed."""

    name: str | None = None
    description: str | None = None
    tactic: str | None = None
    platforms: list[str] | None = None
    status_global: TechniqueStatus | None = None


# ── Read (full) ─────────────────────────────────────────────────────

class TechniqueOut(BaseModel):
    """Complete representation returned by the API."""

    id: uuid.UUID
    mitre_id: str
    name: str
    description: str | None = None
    tactic: str | None = None
    platforms: list[str] | None = None
    mitre_version: str | None = None
    mitre_last_modified: datetime | None = None
    is_subtechnique: bool = False
    parent_mitre_id: str | None = None
    status_global: TechniqueStatus = TechniqueStatus.not_evaluated
    review_required: bool = False
    last_review_date: datetime | None = None

    model_config = ConfigDict(from_attributes=True)


# ── Read (summary) ──────────────────────────────────────────────────

class TechniqueSummary(BaseModel):
    """Lightweight representation used in list endpoints."""

    id: uuid.UUID
    mitre_id: str
    name: str
    tactic: str | None = None
    status_global: TechniqueStatus = TechniqueStatus.not_evaluated

    model_config = ConfigDict(from_attributes=True)
