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

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

/**
 * Configura a API disponível ao interpretador para o jogo Cripto.
 * Registra funções que chamam métodos da `scene` com wrappers do `ApiHelpers`.
 * @param {Object} scene - Instância da cena Phaser (ex.: `CriptoScene`)
 * @param {Object} [config] - Opções (ex.: `animationSpeed`)
 * @returns {Function} Função que realiza o registro no `interpreter` e `globalScope`
 */
export const setupCriptoAPI = (scene, config = {}) => {
  const animationDelay = config.animationSpeed || 500;

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

    ApiHelpers.registerFunction(
      interpreter,
      globalScope,
      "definirSaida",
      ApiHelpers.createActionWrapper(scene, "definirSaida", animationDelay),
      true,
    );

    ApiHelpers.registerFunction(
      interpreter,
      globalScope,
      "definirContador",
      ApiHelpers.createActionWrapper(scene, "definirContador", animationDelay),
      true,
    );

    ApiHelpers.registerFunction(
      interpreter,
      globalScope,
      "concatenarSaida",
      ApiHelpers.createActionWrapper(scene, "concatenarSaida", animationDelay),
      true,
    );

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

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

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

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