from dataclasses import dataclass
from pathlib import Path
from typing import Protocol


@dataclass
class Alert:
    # flat union: "trigger"|"heartbeat"|"levels"|"warn"|"arm"|"prime"|"late_start"|"screenshot"|"status"
    kind: str
    title: str
    body: str
    image_path: Path | None = None  # annotated screenshot
    direction: str | None = None    # "BUY"/"SELL" when kind=trigger
    silent: bool = False            # disable_notification for Telegram; ignored by Discord
    chart_id: str = ""


def _alert_prefix(chart_id: str) -> str:
    """Return Telegram title prefix for chart_id. Empty for single-chart mode."""
    if not chart_id:
        return ""
    if chart_id == "left":
        return "[stânga] "
    if chart_id == "right":
        return "[dreapta] "
    try:
        n = int(chart_id.split("_")[1])
        return f"[chart {n + 1}] "
    except (IndexError, ValueError):
        return f"[{chart_id}] "


class Notifier(Protocol):
    name: str

    def send(self, alert: Alert) -> None: ...  # raises on failure
