"""Kafka topic name constants.

All topic names used across the Dream ecosystem.  Use these enum values
everywhere instead of raw string literals.

Naming convention: ``telegram_message_{domain}_{status}``

Domains: raw | parse | analyze | media | persistence | metrics | events
Statuses: ready | persisted | failed | dead
"""

from __future__ import annotations

from enum import StrEnum


class Topic(StrEnum):
    """All known Kafka topic names in the Dream ecosystem.

    Use these values everywhere instead of raw string literals so that:
    - IDE autocompletion works
    - Renames are tracked by the language server
    - Typos are caught at import time
    """

    # ==================================================================
    # RAW — tele-crawler
    # ==================================================================

    TELEGRAM_MESSAGE_RAW_READY = "telegram_message_raw_ready"
    """Raw Telethon message published by tele-crawler (→ tele-parser, persistence-worker)."""

    TELEGRAM_MESSAGE_RAW_PERSISTED = "telegram_message_raw_persisted"
    """Raw message persisted to DB by persistence-worker."""

    TELEGRAM_MESSAGE_RAW_FAILED = "telegram_message_raw_failed"
    """Errors from tele-crawler — publish failures, auth, network."""

    TELEGRAM_MESSAGE_RAW_DEAD = "telegram_message_raw_dead"
    """Dead letters from tele-crawler — exhausted retries or fatal errors."""

    # ==================================================================
    # PARSE — tele-parser
    # ==================================================================

    TELEGRAM_MESSAGE_PARSE_READY = "telegram_message_parse_ready"
    """Parsed / normalized message published by tele-parser (→ persistence-worker)."""

    TELEGRAM_MESSAGE_PARSE_PERSISTED = "telegram_message_parse_persisted"
    """Parsed message persisted to DB by persistence-worker (→ tele-analyzer)."""

    TELEGRAM_MESSAGE_PARSE_FAILED = "telegram_message_parse_failed"
    """Errors from tele-parser — parse failures, publish failures."""

    TELEGRAM_MESSAGE_PARSE_DEAD = "telegram_message_parse_dead"
    """Dead letters from tele-parser — exhausted retries or non-retryable."""

    # ==================================================================
    # ANALYZE — tele-analyzer
    # ==================================================================

    TELEGRAM_MESSAGE_ANALYZE_READY = "telegram_message_analyze_ready"
    """Analyzed / translated message published by tele-analyzer (→ persistence-worker)."""

    TELEGRAM_MESSAGE_ANALYZE_PERSISTED = "telegram_message_analyze_persisted"
    """Analyzed message persisted to DB by persistence-worker."""

    TELEGRAM_MESSAGE_ANALYZE_FAILED = "telegram_message_analyze_failed"
    """Errors from tele-analyzer — LLM failures, publish failures."""

    TELEGRAM_MESSAGE_ANALYZE_DEAD = "telegram_message_analyze_dead"
    """Dead letters from tele-analyzer — exhausted retries or non-retryable."""

    # ==================================================================
    # MEDIA — media-downloader
    # ==================================================================

    TELEGRAM_MESSAGE_MEDIA_READY = "telegram_message_media_ready"
    """Media download request (→ media-downloader)."""

    TELEGRAM_MESSAGE_MEDIA_PERSISTED = "telegram_message_media_persisted"
    """Media metadata persisted to DB by persistence-worker."""

    TELEGRAM_MESSAGE_MEDIA_FAILED = "telegram_message_media_failed"
    """Errors from media-downloader — download failures, storage failures."""

    TELEGRAM_MESSAGE_MEDIA_DEAD = "telegram_message_media_dead"
    """Dead letters from media-downloader — exhausted retries or non-retryable."""

    # ==================================================================
    # PERSISTENCE — persistence-worker (self-monitoring)
    # ==================================================================

    TELEGRAM_MESSAGE_PERSISTENCE_FAILED = "telegram_message_persistence_failed"
    """Errors from persistence-worker — validation, DB write failures."""

    TELEGRAM_MESSAGE_PERSISTENCE_DEAD = "telegram_message_persistence_dead"
    """Dead letters from persistence-worker — exhausted retries or non-retryable."""

    # ==================================================================
    # METRICS — operational metrics → Doris
    # ==================================================================

    TELEGRAM_MESSAGE_METRICS_READY = "telegram_message_metrics_ready"
    """Per-message crawl/parse metrics from tele-crawler and tele-parser → Doris."""

    TELEGRAM_MESSAGE_METRICS_FAILED = "telegram_message_metrics_failed"
    """Errors in metrics pipeline — publish or write failures."""

    TELEGRAM_MESSAGE_METRICS_DEAD = "telegram_message_metrics_dead"
    """Dead letters from metrics pipeline — exhausted retries."""

    # ==================================================================
    # EVENTS — crawler lifecycle events → Doris
    # ==================================================================

    TELEGRAM_MESSAGE_EVENTS_READY = "telegram_message_events_ready"
    """Crawler lifecycle events (connect, disconnect, errors) → Doris."""

    TELEGRAM_MESSAGE_EVENTS_FAILED = "telegram_message_events_failed"
    """Errors in events pipeline — publish or write failures."""

    TELEGRAM_MESSAGE_EVENTS_DEAD = "telegram_message_events_dead"
    """Dead letters from events pipeline — exhausted retries."""

    # ==================================================================
    # BACKFILL — gap repair jobs (sam-backend → tele-crawler)
    # ==================================================================

    TELEGRAM_BACKFILL_JOB_READY = "telegram_backfill_job_ready"
    """Backfill jobs published by sam-backend gap scanner → tele-crawler workers."""

