"""
Schemi Pydantic per MessageTemplate (Feature 1 – Template messaggi).
"""

import uuid
from datetime import datetime

from pydantic import BaseModel, field_validator


class TemplateCreate(BaseModel):
    name: str
    description: str | None = None
    subject: str = ""
    body_text: str | None = None
    body_html: str | None = None

    @field_validator("name")
    @classmethod
    def name_not_empty(cls, v: str) -> str:
        if not v.strip():
            raise ValueError("Il nome del template non puo' essere vuoto")
        return v.strip()


class TemplateUpdate(BaseModel):
    name: str | None = None
    description: str | None = None
    subject: str | None = None
    body_text: str | None = None
    body_html: str | None = None


class TemplateResponse(BaseModel):
    model_config = {"from_attributes": True}

    id: uuid.UUID
    tenant_id: uuid.UUID
    name: str
    description: str | None = None
    subject: str
    body_text: str | None = None
    body_html: str | None = None
    created_by: uuid.UUID | None = None
    created_at: datetime
    updated_at: datetime


class TemplateListResponse(BaseModel):
    items: list[TemplateResponse]
    total: int
