"""Pydantic schemas for the Report Generator plugin."""

from __future__ import annotations

from datetime import datetime

from pydantic import BaseModel, Field


class TemplateCreate(BaseModel):
    name: str = Field(..., min_length=1, max_length=255)
    description: str = Field("", max_length=2000)
    template_type: str = Field("jinja2", pattern="^(jinja2|sql)$")
    content: str = Field(..., min_length=1)
    output_format: str = Field("csv", pattern="^(csv|excel|json|pdf|print)$")


class TemplateUpdate(BaseModel):
    name: str | None = Field(None, min_length=1, max_length=255)
    description: str | None = Field(None, max_length=2000)
    template_type: str | None = Field(None, pattern="^(jinja2|sql)$")
    content: str | None = None
    output_format: str | None = Field(None, pattern="^(csv|excel|json|pdf|print)$")


class TemplateResponse(BaseModel):
    id: str
    name: str
    description: str
    template_type: str
    content: str
    output_format: str
    created_by: str
    deleted_at: datetime | None = None
    created_at: datetime | None = None
    updated_at: datetime | None = None


class ReportGenerateRequest(BaseModel):
    template_id: str = Field(..., min_length=1)
    data: dict = Field(default_factory=dict)
    output_format: str | None = Field(None, pattern="^(csv|excel|json|pdf|print)$")


class PresetReportRequest(BaseModel):
    """Request to generate a preset report by name."""

    preset: str = Field(
        ...,
        pattern="^(contact_list|calendar_week|calendar_month|company_list|audit_log)$",
    )
    output_format: str = Field("pdf", pattern="^(csv|excel|json|pdf|print)$")
    parameters: dict = Field(default_factory=dict)


class PresetReportInfo(BaseModel):
    """Metadata for a preset report template."""

    key: str
    name: str
    description: str
    icon: str
    output_formats: list[str]


class ReportResponse(BaseModel):
    id: str
    template_id: str
    status: str
    output_path: str | None = None
    error_message: str | None = None
    created_by: str
    created_at: datetime | None = None
    updated_at: datetime | None = None
