// order_metrics_blocks.js

/**
 * Order Metrics Subcategory Blocks Definitions
 *
 * This file defines a set of order metrics-related blocks for Blockly. These blocks
 * enable users to retrieve various order metrics such as order volume, filled orders,
 * unfilled orders, and order status for specified strategies or symbols. 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 defineOrderMetricsBlocks() {

    /**
     * order_volume Block
     *
     * Description:
     * Retrieves the cumulative volume of filled or unfilled orders based on the selected order type.
     * Users can choose the order type (filled/unfilled) from a dropdown instead of connecting a flag block.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "order_volume",
        "message0": "Order Volume for %1 %2",
        "args0": [
            {
                "type": "field_dropdown",
                "name": "ORDER_TYPE",
                "options": [
                    ["Filled Orders", "filled"],
                    ["Unfilled Orders", "unfilled"]
                ],
                "align": "RIGHT"
            },
            {
                "type": "input_value",
                "name": "VALUES",
                "check": "dynamic_value",
                "align": "LEFT"
            }
        ],
        "output": "dynamic_value",
        "colour": 230,
        "tooltip": "Retrieve the cumulative volume of filled or unfilled orders based on the selected order type.",
        "helpUrl": "https://example.com/docs/order_volume"
    }]);

    /**
     * filled_orders Block
     *
     * Description:
     * Retrieves the number of filled orders for the current strategy without specifying a symbol.
     * The block implicitly refers to the current strategy context.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "filled_orders",
        "message0": "Number of Filled Orders %1",
        "args0": [
            {
                "type": "input_value",
                "name": "VALUES",
                "check": "dynamic_value",
                "align": "LEFT"
            }
        ],
        "output": "dynamic_value",
        "colour": 230,
        "tooltip": "Retrieve the total number of filled orders for the current strategy.",
        "helpUrl": "https://example.com/docs/filled_orders"
    }]);

    /**
     * unfilled_orders Block
     *
     * Description:
     * Retrieves the number of unfilled orders for the current strategy without specifying a symbol.
     * The block implicitly refers to the current strategy context.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "unfilled_orders",
        "message0": "Number of Unfilled Orders %1",
        "args0": [
            {
                "type": "input_value",
                "name": "VALUES",
                "check": "dynamic_value",
                "align": "LEFT"
            }
        ],
        "output": "dynamic_value",
        "colour": 230,
        "tooltip": "Retrieve the total number of unfilled orders for the current strategy.",
        "helpUrl": "https://example.com/docs/unfilled_orders"
    }]);

    /**
     * order_status Block
     *
     * Description:
     * Checks if a specified order is in a particular status (Filled, Unfilled, Partial).
     * Outputs a Boolean value indicating the result.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "order_status",
        "message0": "Is %1 Order Status %2",
        "args0": [
            {
                "type": "field_input",
                "name": "ORDER_NAME",
                "text": "order_name",
                "spellcheck": true
            },
            {
                "type": "field_dropdown",
                "name": "order_status",
                "options":[
                    ["Filled", "filled"],
                    ["Unfilled", "unfilled"],
                    ["Partial", "partial"]
                ]
            }
        ],
        "output": "Boolean",
        "colour": 230,
        "tooltip": "Check if the specified order is in the selected status (Filled, Unfilled, Partial). Outputs True if the condition is met, otherwise False.",
        "helpUrl": "https://example.com/docs/order_status"
    }]);
};
