<?php

declare(strict_types=1);

namespace Drupal\flowdrop_node_processor\Plugin\FlowDropNodeProcessor;

use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\flowdrop\Attribute\FlowDropNodeProcessor;
use Drupal\flowdrop\DTO\ParameterBagInterface;
use Drupal\flowdrop\DTO\ValidationResult;
use Drupal\flowdrop\Plugin\FlowDropNodeProcessor\AbstractFlowDropNodeProcessor;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Idea node processor for BPMN-like conceptual flow diagrams.
 *
 * This node type allows users to chain conceptual ideas together without
 * committing to specific implementations. Useful for brainstorming,
 * planning workflows, and creating high-level process diagrams.
 *
 * @internal This class is not part of the public API and may change without notice.
 */
#[FlowDropNodeProcessor(
  id: "idea",
  label: new TranslatableMarkup("Idea"),
  description: "Conceptual idea node for BPMN-like flow diagrams",
  version: "1.0.0"
)]
final class Idea extends AbstractFlowDropNodeProcessor {

  /**
   * {@inheritdoc}
   */
  public static function create(
    ContainerInterface $container,
    array $configuration,
    $plugin_id,
    $plugin_definition,
  ): static {
    return new static($configuration, $plugin_id, $plugin_definition);
  }

  /**
   * {@inheritdoc}
   */
  public function validateParams(array $params): ValidationResult {
    // Idea nodes are conceptual - no required inputs.
    return ValidationResult::success();
  }

  /**
   * {@inheritdoc}
   */
  public function process(ParameterBagInterface $params): array {
    // Idea nodes are primarily visual/conceptual.
    // They pass through their configuration as output data.
    return [
      "instanceTitle" => $params->get("instanceTitle", "New Idea"),
      "instanceDescription" => $params->get("instanceDescription", ""),
      "icon" => $params->get("icon", "mdi:lightbulb-outline"),
      "color" => $params->get("color", "#6366f1"),
      "enableLeftPort" => $params->get("enableLeftPort", TRUE),
      "enableRightPort" => $params->get("enableRightPort", TRUE),
      "enableTopPort" => $params->get("enableTopPort", FALSE),
      "enableBottomPort" => $params->get("enableBottomPort", FALSE),
      "message" => "Idea node content available for reference",
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getParameterSchema(): array {
    return [
      "type" => "object",
      "properties" => [
        "instanceTitle" => [
          "type" => "string",
          "title" => "Title",
          "description" => "The main title or name of your idea",
          "default" => "New Idea",
          "x-display-order" => -2,
        ],
        "instanceDescription" => [
          "type" => "string",
          "title" => "Description",
          "description" => "Detailed description of the idea or concept",
          "format" => "multiline",
          "default" => "Describe your idea here...",
          "x-display-order" => -1,
        ],
        "icon" => [
          "type" => "string",
          "title" => "Icon",
          "description" => "Custom icon for the idea (Iconify format, e.g., mdi:brain)",
          "default" => "mdi:lightbulb-outline",
        ],
        "color" => [
          "type" => "string",
          "title" => "Accent Color",
          "description" => "Accent color for visual grouping (hex format)",
          "default" => "#6366f1",
        ],
        "enableLeftPort" => [
          "type" => "boolean",
          "title" => "Enable Left Port",
          "description" => "Show connection port on the left side (input)",
          "default" => TRUE,
        ],
        "enableRightPort" => [
          "type" => "boolean",
          "title" => "Enable Right Port",
          "description" => "Show connection port on the right side (output)",
          "default" => TRUE,
        ],
        "enableTopPort" => [
          "type" => "boolean",
          "title" => "Enable Top Port",
          "description" => "Show connection port on the top (input)",
          "default" => FALSE,
        ],
        "enableBottomPort" => [
          "type" => "boolean",
          "title" => "Enable Bottom Port",
          "description" => "Show connection port on the bottom (output)",
          "default" => FALSE,
        ],
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getOutputSchema(): array {
    return [
      "type" => "object",
      "properties" => [],
    ];
  }

}
