# shellcheck shell=dash
# https://platform.openai.com/docs/api-reference/images/create

___x_cmd_openai_image(){
    local X_help_cmd='___x_cmd help -m openai image';   help:arg-null:parse
    param:scope     ___x_cmd_openai
    param:subcmd    ___x_cmd_openai_image                       \
        create            "Creates an image given a prompt"     \
        edit              "Creates an edited or extended image" \
        variation         "Creates a variation of a given image"

    param:subcmd:try
    param:run

    ___x_cmd_openai_image _param_help_doc
    return 1
}

___x_cmd_openai_image_create(){
    local X_help_cmd='___x_cmd help -m openai image create';   help:arg-null:parse
    param:scope     ___x_cmd_openai
    param:dsl       '
options:
    --prompt            "A text description of the desired image"                       <>:String
    --n                 "The number of images to generate. Must be between 1 and 10"    <>:Number="1"
    --size              "The size of the generated images"                              <>="1024x1024"  = 1024x1024 1536x1024 1024x1536
    --style             "The style of the generated images"                             <>=""           = vivid natural
    --model             "The model to use for image generation"                         <>="dall-e-2"   = dall-e-2 dall-e-3 gpt-image-1
    --quality           "The quality of the image that will be generated"               <>=""           = standard hd
    --response_format   "The format in which the generated images are returned"         <>="url"        = url b64_json
    --user              "A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse"     <>=""
'
    param:run

    local gen_openai_json="";   gen_openai_json="$(param:option2json -output)"
    openai:debug  --data "$gen_openai_json"
    ___x_cmd_openai_curl post "/images/generations" gen_openai_json
}

___x_cmd_openai_image_edit(){
    local X_help_cmd='___x_cmd help -m openai image edit';   help:arg-null:parse
    param:scope     ___x_cmd_openai
    param:dsl       '
options:
    --image             "The image to edit"                                                         <>
    --prompt            "A text description of the desired image"                                   <>:String
    --n                 "The number of images to generate. Must be between 1 and 10"                <>:Number="1"
    --size              "The size of the generated images"                                          <>="1024x1024"
    --model             "The model to use for image generation"                                     <>="dall-e-2"
    --response_format   "The format in which the generated images are returned"                     <>="url"        = url b64_json
    --user              "A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse"                         <>=""
    --mask              "An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where image should be edited"        <>=""
'
    param:run

    local _image_path="$image"
    local prompt="\"$prompt\""
    ___x_cmd_openai_curl upload /images/edits _image_path prompt n size model response_format user mask
}

___x_cmd_openai_image_variation(){
    local X_help_cmd='___x_cmd help -m openai image variation';   help:arg-null:parse
    param:scope     ___x_cmd_openai
    param:dsl       '
options:
    --image             "The image to use as the basis for the variation"                           <>
    --n                 "The number of images to generate. Must be between 1 and 10"                <>:Number="1"
    --size              "The size of the generated images"                                          <>="1024x1024"
    --model             "The model to use for image generation"                                     <>="dall-e-2"
    --response_format   "The format in which the generated images are returned"                     <>="url"        = url b64_json
    --user              "A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse"                         <>=""
'
    param:run
    local _image_path="$image"
    ___x_cmd_openai_curl upload /images/variations _image_path n size model response_format user
}
