


___x_cmd_minimax_cpstatus(){
    [ $# -gt 0 ]    ||      set -- --auto

    local mode=auto

    while [ $# -gt 0 ]; do
        case "$1" in
            -h|--help)      ___x_cmd help -m minimax cpstatus "$@" ; return 0 ;;
            --auto|--json|--yml|--raw)
                            mode="${1#--}" ; shift ;;
            *)              break ;;
        esac
    done

    ___x_cmd_minimax_cpstatus___"$mode"
}


___x_cmd_minimax_cpstatus___auto(){
    ___x_cmd_minimax_cpstatus___yml
}

___x_cmd_minimax_cpstatus___yml(){
    ___x_cmd_minimax_cpstatus___json | ___x_cmd j2y
}

___x_cmd_minimax_cpstatus___json(){
    ___x_cmd ccmd 10s -- ___x_cmd_minimax_cpstatus___raw | ___x_cmd jq '
        .model_remains[] |= (
            .start_time_human = (.start_time / 1000 | strflocaltime("%Y-%m-%d %H:%M:%S")) |
            .end_time_human = (.end_time / 1000 | strflocaltime("%Y-%m-%d %H:%M:%S")) |
            .remains_time_human = (.remains_time / 1000 |
                "\(. / 3600 | floor)小时\(. % 3600 / 60 | floor)分钟\(. % 60 | floor)秒"
            )
        )
    '
}


___x_cmd_minimax_cpstatus___raw(){
    local codingplan_apikey
    ___x_cmd minimax --cur codingplan_apikey:=   2>/dev/null

    ___x_cmd curl --silent -q --fail --location 'https://www.minimaxi.com/v1/api/openplatform/coding_plan/remains' \
            --header "Authorization: Bearer ${codingplan_apikey}" \
            --header 'Content-Type: application/json'
}
