// values_and_flags.js

/**
 * Values and flags Category Definitions
 *
 * This file defines a set of Value and flag related blocks for Blockly. These blocks
 * enable user notifications, variable management, and flag operations within
 * a strategy or workflow. The use of the "dynamic_value" type allows for flexible
 * chaining with other blocks, enhancing the modularity and interconnectivity of the Blockly environment.
 *
 * Ensure that this file is loaded **after** the `json_base_generator.js` and any other
 * necessary Blockly setup files to maintain proper loading order and functionality.
 */
export function defineValuesAndFlags() {

    /**
     * notify_user Block
     *
     * Description:
     * This block allows users to send customizable notification messages to the user.
     * It can be used to inform about strategy status updates, alerts, or other important events.
     * Supports both static text messages and dynamic values (variables, calculations, etc.).
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "notify_user",
        "message0": "Notify User %1 %2",
        "args0": [
            {
                "type": "field_input",
                "name": "MESSAGE",
                "text": "",
                "spellcheck": true
            },
            {
                "type": "input_value",
                "name": "VALUE",
                "check": ["number", "string", "dynamic_value"],
                "align": "RIGHT"
            }
        ],
        "previousStatement": null,
        "nextStatement": null,
        "colour": 210,
        "tooltip": "Send a notification message to the user. Enter a static message and/or attach dynamic values (variables, calculations). The values will be appended to the message.",
        "helpUrl": "https://example.com/docs/notify_user"
    }]);
    /**
     * value_input Block
     *
     * Description:
     * This block allows users to input a numerical value. Multiple 'Value' blocks can be
     * chained together to create a list of values, enabling flexible data handling.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "value_input",
        "message0": "Value %1 %2",
        "args0": [
            {
                "type": "field_input",
                "name": "VALUE",
                "text": "0",
                "check": "Number" // Enforces numerical input
            },
            {
                "type": "input_value",
                "name": "NEXT",
                "check": "dynamic_value",
                "align": "RIGHT"
            }
        ],
        "output": "dynamic_value",
        "colour": 230,
        "tooltip": "Enter a numerical value. Chain multiple 'Value' blocks to create a list of values.",
        "helpUrl": "https://example.com/docs/value_input"
    }]);
    /**
     * get_variable Block
     *
     * Description:
     * Retrieves the value of a specified variable. This block can be used in expressions,
     * calculations, or conditions where the variable's value is needed.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "get_variable",
        "message0": "Get variable %1 %2",
        "args0": [
            {
                "type": "field_input",
                "name": "variable_name",
                "text": "my_var",
                "check": "String",
                "spellcheck": true
            },
            {
                "type": "input_value",
                "name": "NEXT",
                "check": "dynamic_value",
                "align": "RIGHT"
            }
        ],
        "output": "dynamic_value",
        "colour": 210,
        "tooltip": "Retrieve the current value of the specified variable. Can be used in calculations, conditions, or other operations.",
        "helpUrl": "https://example.com/docs/get_variable"
    }]);

    /**
     * set_variable Block
     *
     * Description:
     * Assigns a specific value to a variable. This block supports setting variables
     * to numerical, string, or dynamic values, allowing for versatile usage within the strategy.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "set_variable",
        "message0": "Set Variable %1 to %2",
        "args0": [
            {
                "type": "field_input",
                "name": "VAR_NAME",
                "text": "variable_name",
                "check": "String",
                "spellcheck": true
            },
            {
                "type": "input_value",
                "name": "VALUE",
                "check": ["number", "string", "dynamic_value"],
                "align": "RIGHT"
            }
        ],
        "previousStatement": null,
        "nextStatement": null,
        "colour": 210,
        "tooltip": "Assign a specific value to a variable. Supports numerical, string, or dynamic values for versatile usage.",
        "helpUrl": "https://example.com/docs/set_variable"
    }]);

    /**
     * set_flag Block
     *
     * Description:
     * Sets a flag to either True or False. Flags can be used to control the flow of the strategy,
     * trigger actions, or maintain state based on certain conditions.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "set_flag",
        "message0": "Set Flag %1 to %2",
        "args0": [
            {
                "type": "field_input",
                "name": "FLAG_NAME",
                "text": "flag_name",
                "check": "String",
                "spellcheck": true
            },
            {
                "type": "field_dropdown",
                "name": "FLAG_VALUE",
                "options": [
                    ["True", "TRUE"],
                    ["False", "FALSE"]
                ]
            }
        ],
        "previousStatement": null,
        "nextStatement": null,
        "colour": 210,
        "tooltip": "Assign a boolean value (True/False) to a specified flag. Flags can be used to control flow, trigger actions, or maintain state within the strategy.",
        "helpUrl": "https://example.com/docs/set_flag"
    }]);

    /**
     * flag_is_set Block
     *
     * Description:
     * Checks whether a specified flag is set to True or False. This block can be used
     * in conditions to control the execution flow based on flag states.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "flag_is_set",
        "message0": "Flag %1 is set %2",
        "args0": [
            {
                "type": "field_input",
                "name": "FLAG_NAME",
                "text": "flag_name",
                "check": "String",
                "spellcheck": true
            },
            {
                "type": "field_dropdown",
                "name": "FLAG_VALUE",
                "options": [
                    ["True", "TRUE"],
                    ["False", "FALSE"]
                ]
            }
        ],
        "output": "Boolean",
        "colour": 210,
        "tooltip": "Evaluate whether the specified flag is set to True or False. Useful for conditional execution or controlling the flow based on flag states.",
        "helpUrl": "https://example.com/docs/flag_is_set"
    }]);
};