# Source code for matchtable.operation

    from typing import Any, Literal, NotRequired, Self, TypedDict
    from uuid import uuid4

    from .i18n import I18nWord, UidRef

    class Operation(TypedDict):
        id: str
        displayedName: str | UidRef
        iconName: NotRequired[str]
        type: NotRequired[str]
        options: NotRequired[dict[str, Any]]

    class OperationBuilder:
        """Create an operation."""

        def __init__(self) -> None:
            self.id = str(uuid4())
            self.name: str | UidRef  # runtime error when not set
            self.options = dict[str, Any]()
            self.icon_name: str | None = None
            self.type: str | None = None

        def set_name(self, name: str) -> Self:
            """Set the name to the operation."""
            self.name = name
            return self

        def set_name_i18n(self, name: I18nWord) -> Self:
            """Set an i18n word as the name of the operation."""
            self.name = UidRef(uid_ref=name["key"], uid_type="i18n")
            return self

        def set_icon(self, icon: str) -> Self:
            """Set the icon to the operation."""
            self.icon_name = icon
            return self

        def set_type(
            self,
            operation_type: str,
        ) -> Self:
            """Set the type to the operation."""
            self.type = operation_type
            return self

        def add_option(self, key: str, value: Any) -> Self:
            """Add an option to the operation."""
            self.options[key] = value
            return self

        def build(self) -> Operation:
            """Obtain the data."""
            op = Operation(id=self.id, displayedName=self.name)
            optional_keys: dict[Literal["iconName", "type", "options"], Any] = {
                "iconName": self.icon_name,
                "type": self.type,
                "options": self.options,
            }
            for key, val in optional_keys.items():
                if val is not None:
                    op[key] = val
            return op