#compdef spessoplayer
# Copyright (C) 2026  unixatch
#
#   it under the terms of the GNU General Public License as published by
#   This program is free software: you can redistribute it and/or modify
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with spessoplayer.  If not, see <https://www.gnu.org/licenses/>.
#

__spessoplayer() {
  local curcontext="$curcontext" prev
  typeset -A opt_args
  cur=$words[CURRENT]
  prev=$words[CURRENT-1]

  case $prev in
    --input | -i | --input[0-9]* | -i[0-9]* | \
    --log-file | -lf)
      _files
      return 0
    ;;
    --volume | \
    --reverb-volume | \
    -vol | -rvb | \
    --volume[0-9]* | \
    --reverb-volume[0-9]* | \
    -vol[0-9]* | \
    -rvb[0-9]*)
      local numbers=({0..100})
      _arguments "*: :(${numbers[@]})"
      return 0
    ;;
    --effects | -e | --effects[0-9]* | -e[0-9]*)
      local effects=(
        "firfit"      "flanger"    "bass"
        "loudness"    "lowpass"    "compand"
        "mcompand"    "noiseprof"  "dither"
        "allpass"     "band"       "echos"
        "bandpass"    "bandreject" "fir"
        "bend"        "biquad"     "ladspa"
        "chorus"      "channels"   "overdrive"
        "contrast"    "dcshift"    "remix"
        "deemph"      "delay"      "sinc"
        "divide"      "downsample" "stats"
        "earwax"      "echo"       "treble"
        "equalizer"   "fade"       "vol"
        "gain"        "highpass"   "repeat"
        "hilbert"     "input"
        "noisered"    "norm"
        "oops"        "output"
        "pad"         "phaser"
        "pitch"       "rate"
        "reverb"      "reverse"
        "riaa"        "silence"
        "spectrogram" "speed"
        "splice"      "stat"
        "stretch"     "swap"
        "synth"       "tempo"
        "tremolo"     "trim"
        "upsample"    "vad"
      )
      _arguments "*: :(${effects[@]})"
      return 0
    ;;
    --loop | \
    --loop-start | \
    --loop-end | \
    -l | -ls | -le | \
    --loop[0-9]* | \
    --loop-start[0-9]* | \
    --loop-end[0-9]* | \
    -l[0-9]* | \
    -ls[0-9]* | \
    -le[0-9]*)
      local numbers=({0..10})
      _arguments "*: :(${numbers[@]})"
      return 0
    ;;
    --sample-rate | \
    -r | \
    --sample-rate[0-9]* | \
    -r[0-9]*)
      local numbers=({0..96000})
      _arguments "*: :(${numbers[@]})"
      return 0
    ;;
    --threads | -T | --max-threads | -mt)
      COMPREPLY=({1..16})
      local numbers=({0..16})
      _arguments "*: :(${numbers[@]})"
      return 0
    ;;
    --format | -f)
      local formats=(
        "wav"
        "flac" "mp3"
        "pcm" "f32le"
      )
      _arguments "*: :(${formats[@]})"
      return 0
    ;;
    --text-delay | -d)
      local numbers=({50..10000})
      _arguments "*: :(${numbers[@]})"
      return 0
    ;;
    --verbose | -v)
      local numbers=({0..3})
      _arguments "*: :(${numbers[@]})"
      return 0
    ;;
  esac

  [[ $cur =~ .* ]] && {
    local all_arguments=(
      "--input"         "-i"
      "--volume"        "-vol"
      "--reverb-volume" "-rvb"
      "--effects"       "-e"
      "--loop"          "-l"
      "--loop-start"    "-ls"
      "--loop-end"      "-le"
      "--sample-rate"   "-r"
      "--format"        "-f"
      "--max-threads"   "-mt"
      "--threads"       "-T"
      "--show-usage"    "-U"
      "--text-delay"    "-d"
      "--no-progress"   "-np"
      "--ask"           "-a"   "--confirm" "-c"
      "--no-table"      "-nt"
      "--dry-run"       "-dr"  "--test" "-t" "--null" "-0"
      "--verbose"       "-v"
      "--log-file"      "-lf"
      "--uninstall"     "-u"
      "--help"          "-h"
      "--version"       "-V"
      "--enable-spessasynth-logging"
      "--enable-spessasynth-warn-logging"
      "--enable-spessasynth-info-logging"
    )
    _arguments "${all_arguments[@]}"
    return 0
  }
}
__spessoplayer

