from dataclasses import dataclass, field
from typing import Any


@dataclass
class ActionSpec:
    action_id: str
    label: str
    style: str = "primary"
    requires_text: bool = False
    payload: dict[str, Any] = field(default_factory=dict)

    def as_dict(self) -> dict[str, Any]:
        return {
            "action_id": self.action_id,
            "label": self.label,
            "style": self.style,
            "requires_text": self.requires_text,
            "payload": self.payload,
        }


@dataclass
class PluginWidget:
    plugin_id: str
    title: str
    logo: str = ""
    description: str = ""
    actions: list[ActionSpec] = field(default_factory=list)
    supports_state: bool = False
    state_refresh_ms: int = 2000

    def as_dict(self) -> dict[str, Any]:
        return {
            "plugin_id": self.plugin_id,
            "title": self.title,
            "logo": self.logo,
            "description": self.description,
            "supports_state": self.supports_state,
            "state_refresh_ms": self.state_refresh_ms,
            "actions": [action.as_dict() for action in self.actions],
        }
