#compdef mycmd

_mycmd() {
  if ((CURRENT == 2)); then
    compadd foo ssh ls
  elif ((CURRENT > 2)); then
    case "$words[2]" in
      (ssh|ls)
        shift words
        ((CURRENT--))
        _normal -p mycmd
        ;;
      (foo)
        _nothing
        ;;
      (*)
        _message "mycmd: invalid subcommand or arguments"
        ;;
    esac
  fi
  return $?
}

# or even, more use of the completion builtin/utility functions like below:

_mycmd() {
  local curcontext="${curcontext}" state context line
  local -A opt_args
  _arguments '*:: :->subcmd'
  if [[ "$state" == "subcmd" ]]; then
    if ((CURRENT == 1)); then
      _describe -t mycmd-subcmd "mycmd command" '(foo ssh ls)'
    else
      curcontext="${curcontext%:*:*}:mycmd-$words[1]:"
      case "$words[1]" in
        (ssh|ls)
          compset -n 1
          _normal -p $service
        ;;
        (foo)
          _nothing
        ;;
        (*)
          _message "mycmd: invalid subcommand or arguments"
        ;;
      esac
    fi
  fi
  return $?
}
