#compdef smart-mount

autoload -U is-at-least

_smart-mount() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_smart-mount_commands" \
"*::: :->smart-mount" \
&& ret=0
    case $state in
    (smart-mount)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:smart-mount-command-$line[1]:"
        case $line[1] in
            (drive)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
":: :_smart-mount__subcmd__drive_commands" \
"*::: :->drive" \
&& ret=0

    case $state in
    (drive)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:smart-mount-drive-command-$line[1]:"
        case $line[1] in
            (add)
_arguments "${_arguments_options[@]}" : \
'--name=[]:NAME:_default' \
'--mount-point=[Where the pair'\''s symlink/backing directories live. Default (on '\''add'\'', derived from the name)\: '\''<mount_base_dir>/<name>'\'' (see '\''settings.mount_base_dir'\''). Ignored on '\''edit'\'' unless explicitly given - an existing pair'\''s mount point stays fixed otherwise, so an active mount doesn'\''t get orphaned]:MOUNT_POINT:_files' \
'--owner-user=[]:OWNER_USER:_default' \
'--local-kind=[]:LOCAL_KIND:(webdav smb nfs)' \
'(--local-mac)--local-ip=[]:LOCAL_IP:_default' \
'(--local-ip)--local-mac=[]:LOCAL_MAC:_default' \
'--local-share=[Meaning depends on '\''--local-kind'\''\: the SMB share name (e.g. '\''media'\''), the NFS export path (e.g. '\''/export/media'\''), or the WebDAV URL path (e.g. '\''/remote.php/dav/files/user'\'')]:LOCAL_SHARE:_default' \
'--local-username=[]:LOCAL_USERNAME:_default' \
'(--local-password-stdin)--local-password=[Insecure (visible in process listing/shell history) - prefer \`--local-password-stdin\` for scripts]:LOCAL_PASSWORD:_default' \
'--cloud-kind=[]:CLOUD_KIND:(webdav smb nfs)' \
'--cloud-host=[]:CLOUD_HOST:_default' \
'--cloud-share=[Meaning depends on '\''--cloud-kind'\''\: the SMB share name (e.g. '\''media'\''), the NFS export path (e.g. '\''/export/media'\''), or the WebDAV URL path (e.g. '\''/remote.php/dav/files/user'\'')]:CLOUD_SHARE:_default' \
'--cloud-username=[]:CLOUD_USERNAME:_default' \
'(--cloud-password-stdin)--cloud-password=[Insecure (visible in process listing/shell history) - prefer \`--cloud-password-stdin\` for scripts]:CLOUD_PASSWORD:_default' \
'--local-password-stdin[Reads the local password as one line from stdin instead of passing it as an argument]' \
'--cloud-password-stdin[Reads the cloud password as one line from stdin instead of passing it as an argument]' \
'--non-interactive[Does not prompt for anything interactively - missing required fields cause an error instead of a prompt (which would fail anyway without a terminal). For scripts/automation]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(edit)
_arguments "${_arguments_options[@]}" : \
'--name=[]:NAME:_default' \
'--mount-point=[Where the pair'\''s symlink/backing directories live. Default (on '\''add'\'', derived from the name)\: '\''<mount_base_dir>/<name>'\'' (see '\''settings.mount_base_dir'\''). Ignored on '\''edit'\'' unless explicitly given - an existing pair'\''s mount point stays fixed otherwise, so an active mount doesn'\''t get orphaned]:MOUNT_POINT:_files' \
'--owner-user=[]:OWNER_USER:_default' \
'--local-kind=[]:LOCAL_KIND:(webdav smb nfs)' \
'(--local-mac)--local-ip=[]:LOCAL_IP:_default' \
'(--local-ip)--local-mac=[]:LOCAL_MAC:_default' \
'--local-share=[Meaning depends on '\''--local-kind'\''\: the SMB share name (e.g. '\''media'\''), the NFS export path (e.g. '\''/export/media'\''), or the WebDAV URL path (e.g. '\''/remote.php/dav/files/user'\'')]:LOCAL_SHARE:_default' \
'--local-username=[]:LOCAL_USERNAME:_default' \
'(--local-password-stdin)--local-password=[Insecure (visible in process listing/shell history) - prefer \`--local-password-stdin\` for scripts]:LOCAL_PASSWORD:_default' \
'--cloud-kind=[]:CLOUD_KIND:(webdav smb nfs)' \
'--cloud-host=[]:CLOUD_HOST:_default' \
'--cloud-share=[Meaning depends on '\''--cloud-kind'\''\: the SMB share name (e.g. '\''media'\''), the NFS export path (e.g. '\''/export/media'\''), or the WebDAV URL path (e.g. '\''/remote.php/dav/files/user'\'')]:CLOUD_SHARE:_default' \
'--cloud-username=[]:CLOUD_USERNAME:_default' \
'(--cloud-password-stdin)--cloud-password=[Insecure (visible in process listing/shell history) - prefer \`--cloud-password-stdin\` for scripts]:CLOUD_PASSWORD:_default' \
'--local-password-stdin[Reads the local password as one line from stdin instead of passing it as an argument]' \
'--cloud-password-stdin[Reads the cloud password as one line from stdin instead of passing it as an argument]' \
'--non-interactive[Does not prompt for anything interactively - missing required fields cause an error instead of a prompt (which would fail anyway without a terminal). For scripts/automation]' \
'-h[Print help]' \
'--help[Print help]' \
':id:_default' \
&& ret=0
;;
(remove)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':id:_default' \
&& ret=0
;;
(list)
_arguments "${_arguments_options[@]}" : \
'--json[Output as JSON instead of a table - for scripts]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_smart-mount__subcmd__drive__subcmd__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:smart-mount-drive-help-command-$line[1]:"
        case $line[1] in
            (add)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(edit)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(remove)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(list)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
;;
(mount)
_arguments "${_arguments_options[@]}" : \
'--name=[Only mount this pair (ID or name)]:NAME:_default' \
'--all[Mount all configured pairs]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(unmount)
_arguments "${_arguments_options[@]}" : \
'--name=[]:NAME:_default' \
'--all[]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(status)
_arguments "${_arguments_options[@]}" : \
'--name=[]:NAME:_default' \
'--json[Output as JSON instead of text - for scripts]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(watch)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(doctor)
_arguments "${_arguments_options[@]}" : \
'--json[Output as JSON instead of text - for scripts]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_smart-mount__subcmd__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:smart-mount-help-command-$line[1]:"
        case $line[1] in
            (drive)
_arguments "${_arguments_options[@]}" : \
":: :_smart-mount__subcmd__help__subcmd__drive_commands" \
"*::: :->drive" \
&& ret=0

    case $state in
    (drive)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:smart-mount-help-drive-command-$line[1]:"
        case $line[1] in
            (add)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(edit)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(remove)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(list)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
(mount)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(unmount)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(status)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(watch)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(doctor)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_smart-mount_commands] )) ||
_smart-mount_commands() {
    local commands; commands=(
'drive:Manage drive pairs (add/edit/remove/list)' \
'mount:Mount configured drive pairs' \
'unmount:Unmount configured drive pairs' \
'status:Shows the current mount status' \
'watch:A single reconcile pass (local/cloud switching) - meant for systemd timers/cron' \
'doctor:Checks prerequisites (binaries, scheduler)' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'smart-mount commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__doctor_commands] )) ||
_smart-mount__subcmd__doctor_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount doctor commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__drive_commands] )) ||
_smart-mount__subcmd__drive_commands() {
    local commands; commands=(
'add:Create a new drive pair (interactive, unless all fields are given via flags)' \
'edit:Edit an existing drive pair - only the given fields change' \
'remove:Remove an existing drive pair' \
'list:List all configured drive pairs' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'smart-mount drive commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__drive__subcmd__add_commands] )) ||
_smart-mount__subcmd__drive__subcmd__add_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount drive add commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__drive__subcmd__edit_commands] )) ||
_smart-mount__subcmd__drive__subcmd__edit_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount drive edit commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__drive__subcmd__help_commands] )) ||
_smart-mount__subcmd__drive__subcmd__help_commands() {
    local commands; commands=(
'add:Create a new drive pair (interactive, unless all fields are given via flags)' \
'edit:Edit an existing drive pair - only the given fields change' \
'remove:Remove an existing drive pair' \
'list:List all configured drive pairs' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'smart-mount drive help commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__drive__subcmd__help__subcmd__add_commands] )) ||
_smart-mount__subcmd__drive__subcmd__help__subcmd__add_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount drive help add commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__drive__subcmd__help__subcmd__edit_commands] )) ||
_smart-mount__subcmd__drive__subcmd__help__subcmd__edit_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount drive help edit commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__drive__subcmd__help__subcmd__help_commands] )) ||
_smart-mount__subcmd__drive__subcmd__help__subcmd__help_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount drive help help commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__drive__subcmd__help__subcmd__list_commands] )) ||
_smart-mount__subcmd__drive__subcmd__help__subcmd__list_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount drive help list commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__drive__subcmd__help__subcmd__remove_commands] )) ||
_smart-mount__subcmd__drive__subcmd__help__subcmd__remove_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount drive help remove commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__drive__subcmd__list_commands] )) ||
_smart-mount__subcmd__drive__subcmd__list_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount drive list commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__drive__subcmd__remove_commands] )) ||
_smart-mount__subcmd__drive__subcmd__remove_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount drive remove commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__help_commands] )) ||
_smart-mount__subcmd__help_commands() {
    local commands; commands=(
'drive:Manage drive pairs (add/edit/remove/list)' \
'mount:Mount configured drive pairs' \
'unmount:Unmount configured drive pairs' \
'status:Shows the current mount status' \
'watch:A single reconcile pass (local/cloud switching) - meant for systemd timers/cron' \
'doctor:Checks prerequisites (binaries, scheduler)' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'smart-mount help commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__help__subcmd__doctor_commands] )) ||
_smart-mount__subcmd__help__subcmd__doctor_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount help doctor commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__help__subcmd__drive_commands] )) ||
_smart-mount__subcmd__help__subcmd__drive_commands() {
    local commands; commands=(
'add:Create a new drive pair (interactive, unless all fields are given via flags)' \
'edit:Edit an existing drive pair - only the given fields change' \
'remove:Remove an existing drive pair' \
'list:List all configured drive pairs' \
    )
    _describe -t commands 'smart-mount help drive commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__help__subcmd__drive__subcmd__add_commands] )) ||
_smart-mount__subcmd__help__subcmd__drive__subcmd__add_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount help drive add commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__help__subcmd__drive__subcmd__edit_commands] )) ||
_smart-mount__subcmd__help__subcmd__drive__subcmd__edit_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount help drive edit commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__help__subcmd__drive__subcmd__list_commands] )) ||
_smart-mount__subcmd__help__subcmd__drive__subcmd__list_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount help drive list commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__help__subcmd__drive__subcmd__remove_commands] )) ||
_smart-mount__subcmd__help__subcmd__drive__subcmd__remove_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount help drive remove commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__help__subcmd__help_commands] )) ||
_smart-mount__subcmd__help__subcmd__help_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount help help commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__help__subcmd__mount_commands] )) ||
_smart-mount__subcmd__help__subcmd__mount_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount help mount commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__help__subcmd__status_commands] )) ||
_smart-mount__subcmd__help__subcmd__status_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount help status commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__help__subcmd__unmount_commands] )) ||
_smart-mount__subcmd__help__subcmd__unmount_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount help unmount commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__help__subcmd__watch_commands] )) ||
_smart-mount__subcmd__help__subcmd__watch_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount help watch commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__mount_commands] )) ||
_smart-mount__subcmd__mount_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount mount commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__status_commands] )) ||
_smart-mount__subcmd__status_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount status commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__unmount_commands] )) ||
_smart-mount__subcmd__unmount_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount unmount commands' commands "$@"
}
(( $+functions[_smart-mount__subcmd__watch_commands] )) ||
_smart-mount__subcmd__watch_commands() {
    local commands; commands=()
    _describe -t commands 'smart-mount watch commands' commands "$@"
}

if [ "$funcstack[1]" = "_smart-mount" ]; then
    _smart-mount "$@"
else
    compdef _smart-mount smart-mount
fi
