"""Domain event type enumeration.

Defines the full set of :class:`EventType` values that domain services
may emit through an :class:`~cleveragents.infrastructure.events.protocol.EventBus`.

Based on:
    - docs/specification.md §Event-Driven Architecture
    - Forgejo issue #473
"""

from __future__ import annotations

from enum import StrEnum


class EventType(StrEnum):
    """Typed identifiers for every domain event the system can emit.

    Values are dot-separated strings following the convention
    ``<domain>.<action>`` (e.g. ``plan.created``).  Using :class:`StrEnum`
    means an :class:`EventType` member compares equal to its string
    representation, which simplifies JSON serialisation and log filtering.
    """

    # --- Plan lifecycle ---
    PLAN_CREATED = "plan.created"
    PLAN_PHASE_CHANGED = "plan.phase_changed"
    PLAN_STATE_CHANGED = "plan.state_changed"
    PLAN_APPLIED = "plan.applied"
    PLAN_CANCELLED = "plan.cancelled"
    PLAN_ERRORED = "plan.errored"
    PLAN_ESTIMATION_COMPLETE = "plan.estimation_complete"

    # --- Decision ---
    DECISION_CREATED = "decision.created"
    DECISION_APPROVED = "decision.approved"
    DECISION_CORRECTED = "decision.corrected"
    DECISION_SUPERSEDED = "decision.superseded"

    # --- Invariant ---
    INVARIANT_RECONCILED = "invariant.reconciled"
    INVARIANT_VIOLATED = "invariant.violated"
    INVARIANT_ENFORCED = "invariant.enforced"

    # --- Actor ---
    ACTOR_INVOKED = "actor.invoked"
    ACTOR_COMPLETED = "actor.completed"
    ACTOR_ERRORED = "actor.errored"
    ACTOR_ESCALATED = "actor.escalated"

    # --- Tool ---
    TOOL_INVOKED = "tool.invoked"
    TOOL_COMPLETED = "tool.completed"
    TOOL_ERRORED = "tool.errored"
    TOOL_RETRIED = "tool.retried"

    # --- Resource ---
    RESOURCE_ACCESSED = "resource.accessed"
    RESOURCE_MODIFIED = "resource.modified"
    RESOURCE_INDEXED = "resource.indexed"

    # --- Correction ---
    CORRECTION_APPLIED = "correction.applied"

    # --- Configuration ---
    CONFIG_CHANGED = "config.changed"

    # --- Entity lifecycle ---
    ENTITY_DELETED = "entity.deleted"

    # --- Authentication (server-mode only) ---
    AUTH_SUCCESS = "auth.success"
    AUTH_FAILURE = "auth.failure"

    # --- Sandbox ---
    SANDBOX_CREATED = "sandbox.created"
    SANDBOX_COMMITTED = "sandbox.committed"
    SANDBOX_ROLLED_BACK = "sandbox.rolled_back"
    CHECKPOINT_CREATED = "checkpoint.created"
    CHECKPOINT_RESTORED = "checkpoint.restored"

    # --- Context ---
    CONTEXT_BUILT = "context.built"
    CONTEXT_QUERY_EXECUTED = "context.query_executed"

    # --- Context tier lifecycle ---
    TIER_PROMOTED = "tier.promoted"
    TIER_DEMOTED = "tier.demoted"
    TIER_EVICTED = "tier.evicted"

    # --- Validation ---
    VALIDATION_STARTED = "validation.started"
    VALIDATION_PASSED = "validation.passed"
    VALIDATION_FAILED = "validation.failed"
    VALIDATION_FIX_ATTEMPTED = "validation.fix_attempted"
    VALIDATION_FIX_SUCCEEDED = "validation.fix_succeeded"
    VALIDATION_FIX_EXHAUSTED = "validation.fix_exhausted"

    # --- Session ---
    SESSION_CREATED = "session.created"
    SESSION_MESSAGE_SENT = "session.message_sent"

    # --- Budget / cost ---
    BUDGET_WARNING = "budget.warning"
    BUDGET_EXCEEDED = "budget.exceeded"


__all__ = ["EventType"]
