"""Type definitions for the Presa SDK."""

from __future__ import annotations

from dataclasses import dataclass
from typing import Literal, Union


NamedFormat = Literal["A4", "Letter", "Legal"]


@dataclass
class CustomFormat:
    """Custom paper dimensions with unit (e.g., '210mm', '8.5in')."""

    width: str
    height: str


PageFormat = Union[NamedFormat, CustomFormat]


@dataclass
class Margins:
    """Page margins with CSS-style unit strings (e.g., '1cm', '0.5in')."""

    top: str | None = None
    right: str | None = None
    bottom: str | None = None
    left: str | None = None


@dataclass
class GenerateOptions:
    """Options for PDF generation."""

    html: str
    """HTML content to convert to PDF."""

    format: PageFormat | None = None
    """Paper format. Defaults to A4."""

    landscape: bool | None = None
    """Use landscape orientation. Defaults to false."""

    margins: Margins | None = None
    """Page margins. Defaults to 1cm on all sides."""

    print_background: bool | None = None
    """Print background graphics. Defaults to true."""

    scale: float | None = None
    """Scale of the content. Between 0.1 and 2.0. Defaults to 1.0."""


@dataclass
class GenerateResult:
    """Result of a PDF generation request."""

    buffer: bytes
    """Raw PDF bytes."""

    size: int
    """Content length in bytes."""


@dataclass
class PresaConfig:
    """Configuration for the Presa client."""

    api_key: str | None = None
    """API key for authentication. Defaults to PRESA_API_KEY env var."""

    base_url: str = "https://api.presa.dev"
    """Base URL of the Presa API."""

    timeout: float = 30.0
    """Request timeout in seconds. Defaults to 30."""
