"""Pydantic schemas for TestTemplate endpoints."""

# Import uuid
import uuid

# Import datetime from datetime
from datetime import datetime

# Import BaseModel, ConfigDict from pydantic
from pydantic import BaseModel, ConfigDict

# ── Full output ─────────────────────────────────────────────────────


class TestTemplateOut(BaseModel):
    """Complete representation of a test template."""

    # id: uuid.UUID
    id: uuid.UUID
    # mitre_technique_id: str
    mitre_technique_id: str
    # name: str
    name: str
    # Assign description = None
    description: str | None = None
    # source: str
    source: str
    # Assign source_url = None
    source_url: str | None = None
    # Assign attack_procedure = None
    attack_procedure: str | None = None
    # Assign expected_detection = None
    expected_detection: str | None = None
    # Assign platform = None
    platform: str | None = None
    # Assign tool_suggested = None
    tool_suggested: str | None = None
    # Assign severity = None
    severity: str | None = None
    # Assign atomic_test_id = None
    atomic_test_id: str | None = None
    # Assign suggested_remediation = None
    suggested_remediation: str | None = None
    # Assign is_active = True
    is_active: bool = True
    # Assign created_at = None
    created_at: datetime | None = None

    # Assign model_config = ConfigDict(from_attributes=True)
    model_config = ConfigDict(from_attributes=True)


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


class TestTemplateCreate(BaseModel):
    """Payload for creating a custom test template."""

    # mitre_technique_id: str
    mitre_technique_id: str
    # name: str
    name: str
    # Assign description = None
    description: str | None = None
    # Assign source = "custom"
    source: str = "custom"
    # Assign source_url = None
    source_url: str | None = None
    # Assign attack_procedure = None
    attack_procedure: str | None = None
    # Assign expected_detection = None
    expected_detection: str | None = None
    # Assign platform = None
    platform: str | None = None
    # Assign tool_suggested = None
    tool_suggested: str | None = None
    # Assign severity = None
    severity: str | None = None
    # Assign atomic_test_id = None
    atomic_test_id: str | None = None
    # Assign suggested_remediation = None
    suggested_remediation: str | None = None


# ── Summary (for listings) ─────────────────────────────────────────


class TestTemplateSummary(BaseModel):
    """Lightweight representation for listing templates."""

    # id: uuid.UUID
    id: uuid.UUID
    # mitre_technique_id: str
    mitre_technique_id: str
    # name: str
    name: str
    # source: str
    source: str
    # Assign platform = None
    platform: str | None = None
    # Assign severity = None
    severity: str | None = None
    # Assign is_active = True
    is_active: bool = True

    # Assign model_config = ConfigDict(from_attributes=True)
    model_config = ConfigDict(from_attributes=True)


# ── Instantiate (create a real Test from a template) ────────────────


class TestTemplateInstantiate(BaseModel):
    """Payload to create a real test from an existing template.

    Optional override fields take precedence over the template values when provided.
    """

    # template_id: uuid.UUID
    template_id: uuid.UUID
    # technique_id: str  # accepts both UUID and MITRE ID (e.g. "T1059.001")
    technique_id: str  # accepts both UUID and MITRE ID (e.g. "T1059.001")

    # User-editable overrides (if omitted the template value is used)
    name: str | None = None
    description: str | None = None
    platform: str | None = None
    procedure_text: str | None = None
    tool_used: str | None = None
