/**
 * @fileoverview Utility module for interpreterSetup.js
 * 
 * @module games.turtle.hooks.interpreterSetup
 */

import { ApiHelpers } from "../../../../interpreters/ApiHelpers.js";

/**
 * Configura e registra as funções do intérprete para o jogo Tartaruga.
 * @param {Object} scene - Referência à cena do Phaser (TurtleScene)
 * @returns {function(interpreter: Object, globalScope: Object): void} Inicializador do interpretador
 */
export const setupTurtleAPI = (scene) => {
  const getAnimationDelay = () => {
    if (scene.executionSpeed >= 75) return 2;
    if (scene.executionSpeed >= 50) return 4;
    if (scene.executionSpeed >= 25) return 10;
    return 10;
  };

  return (interpreter, globalScope) => {
    ApiHelpers.registerFunction(
      interpreter,
      globalScope,
      "move",
      ApiHelpers.createActionWrapper(scene, "move", getAnimationDelay()),
      true,
    );

    ApiHelpers.registerFunction(
      interpreter,
      globalScope,
      "turn",
      ApiHelpers.createActionWrapper(scene, "turn", getAnimationDelay()),
      true,
    );

    ApiHelpers.registerFunction(
      interpreter,
      globalScope,
      "penDown",
      ApiHelpers.createConditionWrapper(scene, "penDown"),
      false,
    );

    ApiHelpers.registerFunction(
      interpreter,
      globalScope,
      "penColour",
      ApiHelpers.createConditionWrapper(scene, "penColour"),
      false,
    );

    ApiHelpers.registerFunction(
      interpreter,
      globalScope,
      "pintarFundo",
      ApiHelpers.createConditionWrapper(scene, "pintarFundo"),
    );

    ApiHelpers.registerFunction(
      interpreter,
      globalScope,
      "highlightBlock",
      ApiHelpers.createHighlightWrapper(scene),
      false,
    );
  };
};

export const TURTLE_COMMANDS = {
  ACTIONS: ["move", "turn"],
  CONDITIONS: ["penDown", "penColour"],
  SPECIAL: ["highlightBlock"],
};
