"""
{{ display_name }} - Process node.

This module handles webhook event processing.
"""

from datetime import datetime, timezone

from state import {{ class_name }}State


async def process(state: {{ class_name }}State) -> dict:
    """Process the validated webhook event.

    Args:
        state: Current handler state.

    Returns:
        Dictionary with state updates including actions taken.
    """
    context = state["context"]

    # Skip processing if validation failed
    if not state.get("is_valid", False):
        context.log_warning("Skipping", "Event failed validation")
        return {
            "current_step": "skipped",
            "processed": False,
            "actions_taken": ["skipped_invalid_event"],
        }

    event_type = state.get("event_type", "")
    payload = state.get("payload", {})

    context.log_progress("Processing", f"Handling {event_type} event")

    # Process based on event type
    actions_taken = []

    if event_type == "created":
        # Handle creation event
        actions_taken.append("logged_creation")
        actions_taken.append("notified_subscribers")

    elif event_type == "updated":
        # Handle update event
        actions_taken.append("logged_update")
        actions_taken.append("synced_changes")

    elif event_type == "deleted":
        # Handle deletion event
        actions_taken.append("logged_deletion")
        actions_taken.append("cleaned_references")

    elif event_type == "triggered":
        # Handle trigger event
        actions_taken.append("executed_trigger")
        actions_taken.append("recorded_execution")

    context.log_success("Processing complete", f"Actions: {len(actions_taken)}")

    return {
        "current_step": "processed",
        "processed": True,
        "actions_taken": actions_taken,
        "metadata": {
            "processed_at": datetime.now(timezone.utc).isoformat(),
            "event_type": event_type,
        },
    }
