##########################################
# WARNING: This is an auto-generated file.
# DO NOT EDIT THIS FILE DIRECTLY
# ANY EDITS WILL BE LOST
##########################################

from dataclasses import dataclass, field
from typing import Any, ClassVar

from ._context import LoadContext, SaveContext


@dataclass
class McpApprovalMode:
    """The approval mode for MCP server tools.
    When kind is "specify", use alwaysRequireApprovalTools and neverRequireApprovalTools
    to control per-tool approval. For "always" and "never", those fields are ignored.

    Attributes
    ----------
    kind : str
        The approval mode: 'always', 'never', or 'specify'
    alwaysRequireApprovalTools : list[str]
        List of tools that always require approval (only used when kind is 'specify')
    neverRequireApprovalTools : list[str]
        List of tools that never require approval (only used when kind is 'specify')
    """

    _shorthand_property: ClassVar[str | None] = "kind"

    kind: str = field(default="")
    alwaysRequireApprovalTools: list[str] = field(default_factory=list)
    neverRequireApprovalTools: list[str] = field(default_factory=list)

    @staticmethod
    def load(data: Any, context: LoadContext | None = None) -> "McpApprovalMode":
        """Load a McpApprovalMode instance.
        Args:
            data (Any): The data to load the instance from.
            context (Optional[LoadContext]): Optional context with pre/post processing callbacks.
        Returns:
            McpApprovalMode: The loaded McpApprovalMode instance.

        """

        if context is not None:
            data = context.process_input(data)

        # handle alternate representations
        if isinstance(data, str):
            data = {"kind": data}

        if not isinstance(data, dict):
            raise ValueError(f"Invalid data for McpApprovalMode: {data}")

        # create new instance
        instance = McpApprovalMode()

        if data is not None and "kind" in data:
            instance.kind = data["kind"]
        if data is not None and "alwaysRequireApprovalTools" in data:
            instance.alwaysRequireApprovalTools = data["alwaysRequireApprovalTools"]
        if data is not None and "neverRequireApprovalTools" in data:
            instance.neverRequireApprovalTools = data["neverRequireApprovalTools"]
        if context is not None:
            instance = context.process_output(instance)
        return instance

    def save(self, context: SaveContext | None = None) -> dict[str, Any]:
        """Save the McpApprovalMode instance to a dictionary.
        Args:
            context (Optional[SaveContext]): Optional context with pre/post processing callbacks.
        Returns:
            dict[str, Any]: The dictionary representation of this instance.

        """
        obj = self
        if context is not None:
            obj = context.process_object(obj)

        result: dict[str, Any] = {}

        if obj.kind is not None:
            result["kind"] = obj.kind
        if obj.alwaysRequireApprovalTools is not None:
            result["alwaysRequireApprovalTools"] = obj.alwaysRequireApprovalTools
        if obj.neverRequireApprovalTools is not None:
            result["neverRequireApprovalTools"] = obj.neverRequireApprovalTools

        if context is not None:
            result = context.process_dict(result)
        return result

    def to_yaml(self, context: SaveContext | None = None) -> str:
        """Convert the McpApprovalMode instance to a YAML string.
        Args:
            context (Optional[SaveContext]): Optional context with pre/post processing callbacks.
        Returns:
            str: The YAML string representation of this instance.

        """
        if context is None:
            context = SaveContext()
        return context.to_yaml(self.save(context))

    def to_json(self, context: SaveContext | None = None, indent: int = 2) -> str:
        """Convert the McpApprovalMode instance to a JSON string.
        Args:
            context (Optional[SaveContext]): Optional context with pre/post processing callbacks.
            indent (int): Number of spaces for indentation. Defaults to 2.
        Returns:
            str: The JSON string representation of this instance.

        """
        if context is None:
            context = SaveContext()
        return context.to_json(self.save(context), indent)
