"""PipelineError domain model — backed by Doris pipeline_errors table."""

from __future__ import annotations

import uuid
from datetime import datetime
from typing import Any, ClassVar

from repo_core.base.models import DomainModel


class PipelineError(DomainModel):
    """Domain model for pipeline errors — Doris warehouse only.

    Maps 1:1 with :class:`broker_core.topics.models.errors.PipelineErrorPayload`
    and the ``pipeline_errors`` Doris table.
    """

    _warehouse_include: ClassVar[set[str]] = {
        "id",
        "error_category",
        "severity",
        "source_service",
        "source_topic",
        "source_partition",
        "source_offset",
        "target_topic",
        "target_operation",
        "telegram_message_id",
        "peer_id",
        "account_id",
        "proxy_id",
        "error_message",
        "error_type",
        "error_traceback",
        "payload_preview",
        "full_payload",
        "payload_truncated",
        "payload_size_bytes",
        "is_retryable",
        "retry_count",
        "max_retries",
        "occurred_at",
        "created_at",
    }
    _timestamps: ClassVar[list[str]] = ["created_at"]

    id: uuid.UUID
    error_category: str
    severity: str = "error"
    source_service: str
    source_topic: str
    source_partition: int | None = None
    source_offset: int | None = None
    target_topic: str | None = None
    target_operation: str | None = None
    telegram_message_id: int | None = None
    peer_id: int | None = None
    account_id: uuid.UUID | None = None
    proxy_id: str | None = None
    error_message: str = ""
    error_type: str = ""
    error_traceback: str | None = None
    payload_preview: str | None = None
    full_payload: dict[str, Any] | None = None
    payload_truncated: bool = False
    payload_size_bytes: int | None = None
    is_retryable: bool = True
    retry_count: int = 0
    max_retries: int = 3
    occurred_at: datetime
    created_at: datetime | None = None
