"""Delete Value node for removing data from the project data store."""

from typing import Any

from flowire_sdk import BaseNode, BaseNodeOutput, NodeExecutionContext, NodeMetadata
from pydantic import BaseModel, Field


class DeleteValueInput(BaseModel):
    """Input schema for Delete Value node."""

    key: str = Field(..., description="Key to delete from the data store")


class DeleteValueOutput(BaseNodeOutput):
    """Output schema for Delete Value node."""

    key: str = Field(..., description="The key that was deleted")
    existed: bool = Field(..., description="Whether the key existed before deletion")


class DeleteValueNode(BaseNode):
    """Delete a value from the project data store."""

    input_schema = DeleteValueInput
    output_schema = DeleteValueOutput

    metadata = NodeMetadata(
        name="Delete Value",
        description="Delete a value from the project data store.",
        category="data",
        icon="🗑️",
        color="#F44336",
    )

    async def execute_logic(
        self,
        validated_inputs: dict[str, Any],
        context: NodeExecutionContext,
    ) -> DeleteValueOutput:
        key = validated_inputs["key"]

        existed = await context.delete_data_store_value(key)

        return DeleteValueOutput(key=key, existed=existed)
