"""Store Value node for persisting data in the project data store."""

from typing import Any

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


class StoreValueInput(BaseModel):
    """Input schema for Store Value node."""

    key: str = Field(..., description="Key to store the value under (max 255 characters)")
    value: str = Field(..., description="Value to store (max 4096 characters)")


class StoreValueOutput(BaseNodeOutput):
    """Output schema for Store Value node."""

    key: str = Field(..., description="The key that was stored")
    value: str = Field(..., description="The value that was stored")


class StoreValueNode(BaseNode):
    """Store a value in the project data store for use across executions."""

    input_schema = StoreValueInput
    output_schema = StoreValueOutput

    metadata = NodeMetadata(
        name="Store Value",
        description="Store a value in the project data store. Values persist across executions.",
        category="data",
        icon="💾",
        color="#4CAF50",
    )

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

        await context.set_data_store_value(key, value)

        return StoreValueOutput(key=key, value=value)
