#compdef podlet

_podlet() {

  local -a commands
  commands=(
    "podman:Generate a Podman Quadlet file from a Podman command"
    "compose:Generate Podman Quadlet files from a compose file"
    "generate:Generate a Podman Quadlet file from an existing object"
    "help:Print this message or the help of the given subcommand/s"
  )

  # local -a options
  # options=(
  #   {-f,--file}'[Generate a file instead of printing to stdout]'
  #   {-u,--unit-directory}'[Generate a file in the Podman unit directory instead of printing to stdout]'
  #   {-n,--name}'[Override the name of the generated file -without the extension-]'
  #   {--overwrite}'[Overwrite existing files when generating a file]'
  #   {--skip-services-check}'[Skip the check for existing services of the same name]'
  #   {-p,--podman-version}'[Podman version generated Quadlet files should conform to]'
  #   {-a,--absolute-host-paths}'[Convert relative host paths to absolute host paths]'
  #   {-d,--description}'[Add a description to the unit]'
  #   {--wants}'[Add (weak) requirement dependencies to the unit]'
  #   {--requires}'[Similar to --wants, but adds stronger requirement dependencies]'
  #   {--binds-to}'[Configure binding dependency between units]'
  #   {--before}'[Configure ordering dependency between units]'
  #   {--after}'[Configure ordering dependency between units]'
  #   {-i,--install}'[Add an \[Install\] section to the unit]'
  #   {--wanted-by}'[Add -weak- parent dependencies to the unit]'
  #   {--required-by}'[Similar to --wanted-by, but adds stronger parent dependencies]'
  #   {-h,--help}'[Print this message or the help of the given subcommand/s]'
  #   {-V,--version}'[Print version]'
  # )

#  options=(
#    "-f --file:Generate a file instead of printing to stdout:file:_files"
#    "-u --unit-directory:Generate a file in the Podman unit directory instead of printing to stdout"
#    "-n --name:Override the name of the generated file (without the extension):name:"
#    "--overwrite:Overwrite existing files when generating a file"
#    "--skip-services-check:Skip the check for existing services of the same name"
#    "-p --podman-version:Podman version generated Quadlet files should conform to:version:(4.4 4.5 4.6 4.7 4.8 5.0)"
#    "-a --absolute-host-paths:Convert relative host paths to absolute host paths:resolve_dir:"
#    "-d --description:Add a description to the unit:description:"
#    "--wants:Add (weak) requirement dependencies to the unit:wants:"
#    "--requires:Similar to --wants, but adds stronger requirement dependencies:requires:"
#    "--binds-to:Configure binding dependency between units:binds_to:"
#    "--before:Configure ordering dependency between units:before:"
#    "--after:Configure ordering dependency between units:after:"
#    "-i --install:Add an [Install] section to the unit"
#    "--wanted-by:Add (weak) parent dependencies to the unit:wanted_by:"
#    "--required-by:Similar to --wanted-by, but adds stronger parent dependencies:required_by:"
#    "-h --help:Print this message or the help of the given subcommand(s)"
#    "-V --version:Print version"
#  )

local curcontext=$curcontext state line

_arguments '*:: :->command' && return
_arguments -C \
  '1:: :->cmds' \
  '2:: :->subcmds' \
&& return 0

case "$state" in
  (command)
    _describe -t commands "podlet command" commands
    ;;
  # (*)
  #   _parseopts -i : o "${options[@]}"
  #   ;;
  (subcmds)
    case "$line[1]" in
      (compose)
        _values 'compose' \
          '--pod[Create `.pod` file and link it with each `.container` file]' \
          '--kube[Create Kubernetes YAML file for a pod instead of separate containers]' \
        && ret=0
        ;;
      (generate)
        _values 'generate' \
          'container[Generate Quadlet file from an existing container]' \
          'pod[Generate Quadlet files from an existing pod and its containers]' \
          'network[Generate Quadlet file from an existing network]' \
          'volume[Generate Quadlet file from an existing volume]' \
          'image[Generate Quadlet file from an image in local storage]' \
          'help[Print this message or the help of the given subcommand(s)]' \
        && ret=0
        ;;
    esac
esac

#  case $state in
#    (file)
#      _files
#      ;;
#    (name)
#      _message "name"
#      ;;
#    (version)
#      _describe -t version "podman version" version
#      ;;
#    (resolve_dir)
#      _directories
#      ;;
#    (description)
#      _message "description"
#      ;;
#    (wants)
#      _message "wants"
#      ;;
#    (binds_to)
#      _message "binds_to"
#      ;;
#    (before)
#      _message "before"
#      ;;
#    (after)
#      _message "after"
#      ;;
#    (wanted_by)
#      _message "wanted_by"
#      ;;
#    (required_by)
#      _message "required_by"
#      ;;
#  esac
}

compdef _podlet podlet
