# shellcheck shell=sh   disable=SC3043,2154

___x_cmd_cf_worker_cron(){
    param:scope     ___x_cmd_cf
    param:subcmd    ___x_cmd_cf_worker_cron         \
        ls              "List worker cron Triggers"         \
        update          "Update a Workers cron Triggers"

    param:subcmd:try
    param:run

    ___x_cmd_cf_worker_cron  _param_help_doc
    return 1
}

# Section: cron ls
# https://developers.cf.com/api/operations/worker-cron-trigger-get-cron-triggers
___x_cmd_cf_worker_cron_ls(){
    param:scope     ___x_cmd_cf
    param:dsl       '
option:
    --script_name       "Name of the script(worker)"        <>:String
    --json|-j           "output in json format"
'
    param:run
    ___x_cmd_cf_param_default

    ___x_cmd_cf_curl get "/accounts/${account_id}/workers/scripts/${script_name}/schedules"
}
# EndSection

# Section: cron update
# https://developers.cf.com/api/operations/worker-cron-trigger-update-cron-triggers
___x_cmd_cf_worker_cron_update(){
    param:scope     ___x_cmd_cf
    param:dsl       '
option:
    --script_name       "Name of the script(worker)"            <>:String
    --cron              "cron expressions"                      <>:String
    --json|-j           "output in json format"
'
    param:run
    ___x_cmd_cf_param_default

    local gen_cf_json=""
    gen_cf_json="$(printf '[%s]' "$(param:option2json -script_name)")"
    cf:debug "data: $gen_cf_json"
    ___x_cmd_cf_curl put "/accounts/${account_id}/workers/scripts/${script_name}/schedules" gen_cf_json
}
# EndSection
