"""Report schemas."""

from datetime import datetime
from typing import Optional, List
from uuid import UUID
from pydantic import BaseModel, Field, ConfigDict
from enum import Enum


class ReportFormat(str, Enum):
    """Report format enum."""

    PDF = "pdf"
    CSV = "csv"


class ReportSection(str, Enum):
    """Report section enum."""

    SUMMARY = "summary"
    COSTS = "costs"
    METRICS = "metrics"
    LOGS = "logs"
    PII = "pii"


class ReportStatus(str, Enum):
    """Report generation status enum."""

    PENDING = "pending"
    PROCESSING = "processing"
    COMPLETED = "completed"
    FAILED = "failed"


class ReportCreateRequest(BaseModel):
    """Schema for report generation request."""

    format: ReportFormat = Field(..., description="Report format (pdf or csv)")
    include_logs: bool = Field(
        default=True, description="Include individual log entries"
    )
    date_from: Optional[datetime] = Field(None, description="Start date filter")
    date_to: Optional[datetime] = Field(None, description="End date filter")
    sections: List[ReportSection] = Field(
        default=[
            ReportSection.SUMMARY,
            ReportSection.COSTS,
            ReportSection.METRICS,
            ReportSection.LOGS,
            ReportSection.PII,
        ],
        description="Sections to include in PDF report",
    )


class ReportResponse(BaseModel):
    """Schema for report response."""

    model_config = ConfigDict(from_attributes=True)

    id: UUID
    scenario_id: UUID
    format: ReportFormat
    file_path: str
    file_size_bytes: Optional[int] = None
    generated_by: Optional[str] = None
    created_at: datetime
    updated_at: datetime


class ReportStatusResponse(BaseModel):
    """Schema for report status response."""

    report_id: UUID
    status: ReportStatus
    progress: int = Field(
        default=0, ge=0, le=100, description="Generation progress percentage"
    )
    message: Optional[str] = None
    file_path: Optional[str] = None
    file_size_bytes: Optional[int] = None
    created_at: Optional[datetime] = None
    completed_at: Optional[datetime] = None


class ReportList(BaseModel):
    """Schema for list of reports."""

    items: List[ReportResponse]
    total: int
    page: int
    page_size: int


class ReportGenerateResponse(BaseModel):
    """Schema for report generation accepted response."""

    report_id: UUID
    status: ReportStatus
    message: str
