#!/bin/bash
# Premium TiKV disk report helper.
# Usage:
#   source o11y-premium-disk.sh
#   o11y_premium_tikv_disk_report <cluster_id> [window] [subquery_step_seconds] [time_ts_or_iso8601] [provider]
# The shell helper intentionally delegates to o11y-inspect.py so premium disk
# logic stays in one implementation path.

if [ -n "${BASH_SOURCE[0]:-}" ]; then
    _O11Y_DATA_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
else
    _O11Y_DATA_ROOT="$(cd "$(dirname "$0")" && pwd)"
fi

source "${_O11Y_DATA_ROOT}/o11y-data.sh"

o11y_premium_tikv_disk_report() {
    local cluster_id="${1:?Usage: o11y_premium_tikv_disk_report <cluster_id> [window] [subquery_step_seconds] [time_ts_or_iso8601] [provider]}"
    local window="${2:-1h}"
    local subquery_step_seconds="${3:-60}"
    local time_ts="${4:-$(date +%s)}"
    local provider="${5:-aws}"
    local python_bin="${PYTHON_BIN:-python3}"
    local inspect_script="${_O11Y_DATA_ROOT}/o11y-inspect.py"

    if ! command -v "$python_bin" >/dev/null 2>&1; then
        echo "ERROR: ${python_bin} not found" >&2
        return 1
    fi

    "$python_bin" "$inspect_script" "$cluster_id" \
        --provider "$provider" \
        --premium-disk-report \
        --window "$window" \
        --subquery-step-seconds "$subquery_step_seconds" \
        --time-ts "$time_ts"
}

if [ -n "${BASH_VERSION:-}" ]; then
    export -f o11y_premium_tikv_disk_report
fi
