"""Shared cancel + step watchdog for Avatar plan execution."""

from __future__ import annotations

import threading
from dataclasses import dataclass, field

DEFAULT_PLAN_STEP_MAX_SEC = 120.0
INTERACTIVE_MODAL_MAX_SEC = 300.0
VISION_RECOVERY_MODAL_MAX_SEC = 120.0


@dataclass
class PlanExecutionControl:
    """Thread-safe cancel signal shared between UI and plan worker."""

    _cancel_event: threading.Event = field(default_factory=threading.Event)

    def request_cancel(self) -> None:
        self._cancel_event.set()

    def clear(self) -> None:
        self._cancel_event.clear()

    def is_cancelled(self) -> bool:
        return self._cancel_event.is_set()

    @property
    def cancel_event(self) -> threading.Event:
        return self._cancel_event
