"""Response types for the Baponi SDK."""

from __future__ import annotations

from pydantic import BaseModel, ConfigDict


class SandboxResult(BaseModel):
    """Result of a sandbox code execution.

    Returned for all successful API calls, including executions that exited
    with a non-zero exit code. Check ``success`` or ``exit_code`` to
    determine whether the code itself succeeded.
    """

    model_config = ConfigDict(frozen=True)

    success: bool
    stdout: str
    stderr: str
    exit_code: int
    error: str | None = None


class SignedUrlHeader(BaseModel):
    """A header that must be included when using a signed URL."""

    model_config = ConfigDict(frozen=True)

    name: str
    value: str


class SignedUrl(BaseModel):
    """A signed URL for direct file upload or download."""

    model_config = ConfigDict(frozen=True)

    url: str
    method: str
    headers: list[SignedUrlHeader] = []
    expires_at: str


class FileEntry(BaseModel):
    """A file entry from a list operation."""

    model_config = ConfigDict(frozen=True)

    path: str
    size: int
    modified: str | None = None


class ExecutionStatus(BaseModel):
    """Status of an execution (GET /v1/executions/{trace_id} response)."""

    model_config = ConfigDict(frozen=True)

    trace_id: str
    status: str
    exit_code: int | None = None
    stdout: str | None = None
    stderr: str | None = None
    error: str | None = None
    duration_ms: int = 0
    delivery_mode: str = "inline"
    created_at: str = ""
    completed_at: str | None = None
    webhook_url: str | None = None
    webhook_delivery_status: str | None = None


class CancelResponse(BaseModel):
    """Response from POST /v1/executions/{trace_id}/cancel."""

    model_config = ConfigDict(frozen=True)

    trace_id: str
    status: str


class WebhookAccepted(BaseModel):
    """202 Accepted response from webhook execution."""

    model_config = ConfigDict(frozen=True)

    trace_id: str
    status: str
