// trade_metrics_blocks.js

/**
 * Trade Metrics Subcategory Blocks Definitions
 *
 * This file defines a set of trade metrics-related blocks for Blockly. These blocks
 * enable users to retrieve various trade metrics such as active trades, total trades,
 * last trade details, average entry price, unrealized profit/loss, and user active trades.
 * 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 defineTradeMetricsBlocks() {

    /**
     * active_trades Block
     *
     * Description:
     * Retrieves the number of active trades currently open by this strategy.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "active_trades",
        "message0": "Active Strategy Trades %1",
        "args0": [
            {
                "type": "input_value",
                "name": "VALUES",
                "check": "dynamic_value",
                "align": "LEFT"
            }
        ],
        "output": "dynamic_value",
        "colour": 230,
        "tooltip": "Retrieve the number of active trades currently open by this strategy.",
        "helpUrl": "https://example.com/docs/active_trades"
    }]);

    /**
     * total_trades Block
     *
     * Description:
     * Retrieves the total number of trades executed by this strategy.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "total_trades",
        "message0": "Total Trades %1",
        "args0": [
            {
                "type": "input_value",
                "name": "VALUES",
                "check": "dynamic_value",
                "align": "LEFT"
            }
        ],
        "output": "dynamic_value",
        "colour": 230,
        "tooltip": "Retrieve the total number of trades executed by this strategy.",
        "helpUrl": "https://example.com/docs/total_trades"
    }]);

    /**
     * last_trade_details Block
     *
     * Description:
     * Retrieves comprehensive details of the most recent trade executed this strategy.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "last_trade_details",
        "message0": "%1 of Last Trade %2",
        "args0": [
                    {
                "type": "field_dropdown",
                "name": "DETAILS",
                "options": [
                    ["Price", "price"],
                    ["Volume", "volume"],
                    ["Direction", "direction"]
                ],
                "align": "RIGHT"
            },
            {
                "type": "input_value",
                "name": "VALUES",
                "check": "dynamic_value",
                "align": "LEFT"
            }
        ],
        "output": "dynamic_value",
        "colour": 230,
        "tooltip": "Retrieve price, volume, or direction details of the most recent trade executed by this strategy.",
        "helpUrl": "https://example.com/docs/last_trade_details"
    }]);

    /**
     * average_entry_price Block
     *
     * Description:
     * Retrieves the average entry price of all open positions within this strategy.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "average_entry_price",
        "message0": "Average Entry Price %1",
        "args0": [
            {
                "type": "input_value",
                "name": "VALUES",
                "check": "dynamic_value",
                "align": "LEFT"
            }
        ],
        "output": "dynamic_value",
        "colour": 230,
        "tooltip": "Retrieve the average entry price of all open positions for this strategy.",
        "helpUrl": "https://example.com/docs/average_entry_price"
    }]);

    /**
     * unrealized_profit_loss Block
     *
     * Description:
     * Retrieves the total unrealized profit or loss across all current positions of this strategy.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "unrealized_profit_loss",
        "message0": "Unrealized P/L %1",
        "args0": [
            {
                "type": "input_value",
                "name": "VALUES",
                "check": "dynamic_value",
                "align": "LEFT"
            }
        ],
        "output": "dynamic_value",
        "colour": 230,
        "tooltip": "Retrieve the total unrealized profit or loss across all current positions for this strategy.",
        "helpUrl": "https://example.com/docs/unrealized_profit_loss"
    }]);

    /**
     * user_active_trades Block
     *
     * Description:
     * Retrieves the number of active trades across all strategies and symbols for the user.
     * This provides an aggregate view of the user's active trading positions.
     */
    Blockly.defineBlocksWithJsonArray([{
        "type": "user_active_trades",
        "message0": "Active User Trades %1",
        "args0": [
            {
                "type": "input_value",
                "name": "VALUES",
                "check": "dynamic_value"
            }
        ],
        "output": "dynamic_value",
        "colour": 230,
        "tooltip": "Retrieve the total number of active trades across all strategies and symbols for the user.",
        "helpUrl": "https://example.com/docs/user_active_trades"
    }]);
}