// risk_management_blocks.js

/**
 * Risk Management Blocks Category Definitions
 *
 * This file defines a set of risk management-related blocks for Blockly. These blocks
 * enable users to manage and retrieve various risk metrics such as leverage, margin,
 * risk ratio, and maximum position size. The use of "dynamic_value" types 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 defineRiskManagementBlocks() {

    /**
     * set_leverage Block
     *
     * Description:
     * Allows users to set the leverage ratio for their trading strategy. Higher leverage
     * can amplify both potential profits and risks.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "set_leverage",
        "message0": "Set Leverage to %1",
        "args0": [
            {
                "type": "input_value",
                "name": "LEVERAGE",
                "check": ["number", "dynamic_value"],
                "align": "RIGHT"
            }

        ],
        "previousStatement": null,
        "nextStatement": null,
        "colour": 330,
        "tooltip": "Set the leverage ratio for trades executed by the strategy. Higher leverage increases both potential profits and risks.",
        "helpUrl": "https://example.com/docs/set_leverage"
    }]);

    /**
     * current_margin Block
     *
     * Description:
     * Retrieves the current margin balance utilized by the trading strategy. This metric
     * helps in assessing the strategy's exposure and ensuring it operates within defined limits.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "current_margin",
        "message0": "Current Margin %1",
        "args0": [
            {
                "type": "input_value",
                "name": "NEXT",
                "check": "dynamic_value",
                "align": "LEFT"
            }
        ],
        "output": "dynamic_value",
        "colour": 330,
        "tooltip": "Retrieve the current margin balance utilized by the trading strategy.",
        "helpUrl": "https://example.com/docs/current_margin"
    }]);

    /**
     * risk_ratio Block
     *
     * Description:
     * Calculates and retrieves the current risk ratio of the trading strategy. The risk ratio
     * indicates the balance between potential profits and risks, helping in evaluating
     * the strategy's risk management effectiveness.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "risk_ratio",
        "message0": "Risk Ratio %1",
        "args0": [
            {
                "type": "input_value",
                "name": "NEXT",
                "check": "dynamic_value",
                "align": "LEFT"
            }
        ],
        "output": "dynamic_value",
        "colour": 330,
        "tooltip": "Calculate and retrieve the current risk ratio, indicating the balance between potential profits and risks in the strategy.",
        "helpUrl": "https://example.com/docs/risk_ratio"
    }]);

    /**
     * max_position_size Block
     *
     * Description:
     * Sets a maximum limit on the number of concurrent positions the trading strategy can hold.
     * This helps in managing exposure and mitigating risks associated with over-leveraging.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "max_position_size",
        "message0": "Set Max Position Size %1",
        "args0": [
            {
                "type": "input_value",
                "name": "MAX_SIZE",
                "check": ["number", "dynamic_value"],
                "align": "RIGHT"
            }
        ],
        "previousStatement": null,
        "nextStatement": null,
        "colour": 330,
        "tooltip": "Set a maximum limit on the number of concurrent positions the trading strategy can hold. This helps in managing exposure and mitigating risks.",
        "helpUrl": "https://example.com/docs/max_position_size"
    }]);
};