# shellcheck shell=dash disable=SC2034,SC2154
___x_cmd_gddy_domain_record_edit(){
    local X_help_cmd='x help -m gddy domain record edit';    help:arg:parse
    param:scope     ___x_cmd_gddy
    param:dsl    '
options:
    #1             "Domain"                                                             <>
    --type         "Type"                                                               <>=""      = A AAAA CNAME MX NS SOA SRV TXT
    --data         "Value(xx.xx.xx.xx)"                                                 <>
    --ttl          "Time To Live"                                                       <>=1800    = 0 1800 3600
    --name         "Name"                                                               <>
    --shopper_id   "Shopper ID which owns the domain"                                   <>=""
    --port         "Service port"                                                       <>="65535"
    --priority     "Record priority (MX and SRV only)"                                  <>=0
    --protocol     "Service protocol (SRV only)"                                        <>="SRV"
    --service      "Service type (SRV only)"                                            <>="SRV"
    --weight       "Record weight (SRV only)"                                           <>=0

    --json|-j      "output raw JSON data"
'
    param:run
    gddy:arg:format:raw:json2app:all

    if [ -z "$type" ]; then
        if x is ip "$data"; then
            gddy:info "$data is recognized as IPv4 address, record type set to A"
            type=A
        else
            gddy:info "$data is not an IP Address; record type set to CNAME"
            type=CNAME
        fi
    fi
    local ___X_CMD_GDDY_RECORD_REQUEST=1
    local gen_gddy_json=""
    gen_gddy_json="$(param:option2json -shopper_id)"
    gen_gddy_json="$(x jo list $gen_gddy_json)"
    gddy:debug "$gen_gddy_json"

    ___x_cmd_gddy_domain_record_rm  --type "${type}" --name "$name" --yes "$1" || return

    ___x_cmd_gddy_domain_record_edit___"${format}" "$@"

}

___x_cmd_gddy_domain_record_edit___app(){
    local err_msg=
    local data; data="$( ___x_cmd_gddy_domain_record_edit___json "$@" )" || ourl:data:ret
    ___x_cmd_pipevar    data    x jo env err_msg=.message

    if  ! ___x_cmd_gddy_http_error; then
        ___x_cmd_ui_tf false "Domain add Dns failure: $err_msg"
        return 1
    else
        ___x_cmd_ui_tf true "[Success]: Domain add Dns successful"
    fi
}


___x_cmd_gddy_domain_record_edit___json(){
    local data; data="$( ___x_cmd_gddy_domain_record_edit___raw "$@" )" || ourl:data:ret
    ___x_cmd_pipevar    data
}

___x_cmd_gddy_domain_record_edit___raw(){
    ___x_cmd_gddy_ourl patch "/v1/domains/$1/records"
}
