/**
 * Balances Subcategory Blocks Definitions
 *
 * Note:
 * - All blocks except 'set_available_strategy_balance' accept a 'dynamic_value' input named 'VALUES'.
 * - These blocks output a 'dynamic_value' containing the result and any unused input values.
 * - The 'set_available_strategy_balance' block is a statement block that accepts a 'dynamic_value' input or a number.
 */

export function defineBalanceBlocks() {

    // Register the 'dynamic_value' type if not already registered
    Blockly.Types = Blockly.Types || {};
    Blockly.Types.DYNAMIC_VALUE = 'dynamic_value';

    /**
     * Starting Balance Block
     *
     * Retrieves the starting balance of the strategy.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "starting_balance",
        "message0": "Starting Balance %1",
        "args0": [
            {
                "type": "input_value",
                "name": "VALUES",
                "check": "dynamic_value"
            }
        ],
        "output": "dynamic_value",
        "colour": 230,
        "tooltip": "Retrieve the starting balance of the strategy. Attach additional values to forward them.",
        "helpUrl": ""
    }]);

    /**
     * Current Balance Block
     *
     * Retrieves the current balance of the strategy.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "current_balance",
        "message0": "Current Balance %1",
        "args0": [
            {
                "type": "input_value",
                "name": "VALUES",
                "check": "dynamic_value"
            }
        ],
        "output": "dynamic_value",
        "colour": 230,
        "tooltip": "Retrieve the current balance of the strategy. Attach additional values to forward them.",
        "helpUrl": ""
    }]);

    /**
     * Available Balance Block
     *
     * Retrieves the overall available (liquid) balance of the user.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "available_balance",
        "message0": "Available Balance %1",
        "args0": [
            {
                "type": "input_value",
                "name": "VALUES",
                "check": "dynamic_value"
            }
        ],
        "output": "dynamic_value",
        "colour": 230,
        "tooltip": "Retrieve the overall available (liquid) balance. Attach additional values to forward them.",
        "helpUrl": ""
    }]);

    /**
     * Available Strategy Balance Block
     *
     * Retrieves the available balance allocated specifically to the strategy.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "available_strategy_balance",
        "message0": "Available Strategy Balance %1",
        "args0": [
            {
                "type": "input_value",
                "name": "VALUES",
                "check": "dynamic_value"
            }
        ],
        "output": "dynamic_value",
        "colour": 230,
        "tooltip": "Retrieve the available balance allocated to the strategy. Attach additional values to forward them.",
        "helpUrl": ""
    }]);

    /**
     * Set Available Strategy Balance Block
     *
     * Sets the balance allocated to the strategy.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "set_available_strategy_balance",
        "message0": "Set Available Strategy Balance to %1",
        "args0": [
            {
                "type": "input_value",
                "name": "BALANCE",
                "check": ["number", "dynamic_value"]
            }
        ],
        "previousStatement": null,
        "nextStatement": null,
        "colour": 230,
        "tooltip": "Set the balance allocated to the strategy. Accepts a number or the first value from a dynamic list.",
        "helpUrl": ""
    }]);
}
