from typing import Any

from pydantic import Field

"""
Dynamic CLI Action Model.

Replaces hardcoded EnumNodeCliAction with extensible model that
enables plugin extensibility and contract-driven action registration.
"""

from pydantic import BaseModel


class ModelCliAction(BaseModel):
    """
    Dynamic CLI action model that reads from contracts.

    Replaces hardcoded EnumNodeCliAction to allow third-party nodes
    to register their own actions dynamically.
    """

    action_name: str = Field(
        default=...,
        description="Action identifier",
        pattern="^[a-z][a-z0-9_]*$",
    )
    node_name: str = Field(default=..., description="Node that provides this action")
    description: str = Field(default=..., description="Human-readable description")
    deprecated: bool = Field(default=False, description="Whether action is deprecated")
    category: str | None = Field(
        default=None, description="Action category for grouping"
    )

    @classmethod
    def from_contract_action(
        cls,
        action_name: str,
        node_name: str,
        description: str | None = None,
        **kwargs: Any,
    ) -> "ModelCliAction":
        """Factory method for creating actions from contract data."""
        return cls(
            action_name=action_name,
            node_name=node_name,
            description=description or f"{action_name} action for {node_name}",
            **kwargs,
        )

    def get_qualified_name(self) -> str:
        """Get fully qualified action name."""
        return f"{self.node_name}:{self.action_name}"

    def matches(self, action_name: str) -> bool:
        """Check if this action matches the given action name."""
        return self.action_name == action_name
