"""Crawler event — lifecycle and error events (warehouse-only).

Captures every operational happening in the tele-crawler lifecycle:
connects, disconnects, reconnects, auth errors, flood waits, and more.

This is a **warehouse-only** model — no PostgreSQL or Elasticsearch
backing.  All dashboard queries run against Doris.
"""

from __future__ import annotations

import uuid
from datetime import datetime
from typing import Any

from repo_core.base.models import DomainModel


class CrawlerEvent(DomainModel):
    """Operational lifecycle event for dashboard monitoring.

    Usage::

        event = CrawlerEvent(
            id=uuid.uuid4(),
            account_id=uuid.uuid4(),
            proxy_id="d-17432776848",
            crawler_instance_id="tele-crawler-abc123",
            event_type="connect",
            event_data=None,
        )
        row = event.to_warehouse()
    """

    id: uuid.UUID
    account_id: uuid.UUID | None = None
    proxy_id: str | None = None
    crawler_instance_id: str
    event_type: str
    event_data: dict[str, Any] | None = None
    created_at: datetime | None = None

    # Warehouse-only — no DB or search backends
    _warehouse_include: set[str] | None = {
        "id",
        "account_id",
        "proxy_id",
        "crawler_instance_id",
        "event_type",
        "event_data",
        "created_at",
    }

    _db_include: set[str] | None = set()
    _search_include: set[str] | None = set()
    _timestamps: set[str] = {"created_at"}
