#autoload

# Copyright C 2008-2009 by Isilon Systems, Inc. All rights not expressly
# granted herein are reserved.
# Created in the United States of America.
#
# This digital media is protected by U.S. and international copyright and
# intellectual property laws. Unless otherwise specified, all information
# and screens appearing as part of this digital medium, including
# software, services, documents, text, images, icons, and logos design;
# the selection, assembly, arrangement, and design thereof; and the code
# that enables its presentation, are the sole property of Isilon Systems,
# Inc.
#
# Except as otherwise required by applicable law, no part of any
# copyrighted material may be reproduced, modified, translated,
# distributed, published, or transmitted by any means, electronic or
# mechanical, for any purpose, without the prior written consent of Isilon
# Systems.
#
# Isilon and Isilon Systems are registered trademarks of Isilon Systems,
# Inc.  Legion is a trademark of Isilon Systems, Inc.  All other
# trademarks and registered trademarks are the property of their
# respective holders.


(( $+functions[__isi_classic_snapshot] )) ||
_isi_classic_snapshot() {
  if (( CURRENT == 2 )); then
    _tags values && { compadd $@ create add modify change rename mv move delete rm remove list ls usage schedule lock enable disable autocreate autodelete reserve settings }
  else
    local cmd=${words[2]}
    (( CURRENT-- ))
    shift words
    if [[ $cmd == create || $cmd == add ]]; then
      if (( CURRENT > 2 )); then
        _arguments '*::path:_isi_path'
      fi
    elif [[ $cmd == schedule ]]; then
      curcontext="${curcontext%:*:*}:isi-snapshot-schedule:"
      _isi_classic_snapshot_schedule
    elif [[ $cmd == lock ]]; then
      curcontext="${curcontext%:*:*}:isi-snapshot-lock:"
      _isi_classic_snapshot_lock
    elif [[ $cmd == settings ]]; then
      curcontext="${curcontext%:*:*}:isi-snapshot-settings:"
      _isi_classic_snapshot_settings
    else
      curcontext="${curcontext%:*:*}:isi-snapshot-snaps:"
      _isi_classic_snapshot_snaps
    fi
  fi
}

(( $+functions[_isi_classic_snapshot_schedule] )) ||
_isi_classic_snapshot_schedule() {
  if (( CURRENT == 2 )); then
    _tags values && { compadd $@ list ls todo pending create add modify change delete rm remove rename mv move }
  else
    local cmd=${words[2]}
    (( CURRENT-- ))
    shift words
    if [[ $cmd == create || $cmd == add ]]; then
      if (( CURRENT > 4 )); then
        _arguments '*::path:_isi_path'
      fi
    elif [[ $cmd != todo && $cmd != pending ]]; then
      curcontext="${curcontext%:*:*}:isi-snapshot-scheds:"
      _isi_classic_snapshot_scheds
    fi
  fi
}

(( $+functions[_isi_classic_snapshot_lock] )) ||
_isi_classic_snapshot_lock() {
  if (( CURRENT == 2 )); then
    _tags values && { compadd $@ list ls create add modify change delete rm remove }
  elif (( CURRENT == 3 )); then
    _isi_snaps=(
      $(/usr/bin/isi_classic snapshot list | /usr/bin/awk '{print $1}')
    )
    _tags values && { compadd $@ $_isi_snaps }
  elif (( CURRENT == 4 )); then
    local cmd=${words[2]}
    if [[ $cmd != create && $cmd != list && $cmd != add ]]; then
      _isi_locks=(
        $(/usr/bin/isi_classic snapshot lock list ${words[3]} | /usr/bin/awk ' !/\*/ {print $1}')
      )
      _tags values && { compadd $@ $_isi_locks }
    fi
  fi
}

(( $+functions[_isi_classic_snapshot_settings] )) ||
_isi_classic_snapshot_settings() {
  if (( CURRENT == 2 )); then
    _tags values && { compadd $@ list ls set }
  elif (( CURRENT == 3 )); then
    _isi_settings=(
      $(/usr/bin/isi_classic snapshot settings list | /usr/bin/awk ' !/Setting|-/ {print $1}')
    )
    _tags values && { compadd $@ $_isi_settings }
  elif (( CURRENT == 4 )); then
    local cmd=${words[2]}
    if [[ $cmd == set ]]; then
      _tags values && { compadd $@ true false }
    fi
  fi
}

(( $+functions[_isi_classic_snapshot_snaps] )) ||
_isi_classic_snapshot_snaps() {
  _isi_snaps=(
    $(/usr/bin/isi_classic snapshot list | /usr/bin/awk '{print $1}')
  )
  local cmd=${words[1]}
  if [[ $cmd == delete || $cmd == remove || $cmd == rm || $cmd == ls || $cmd == list ]]; then
    if (( CURRENT > 1)); then
      _tags values && { compadd $@ $_isi_snaps }
    fi
  else
    if (( CURRENT == 2 )); then
      _tags values && { compadd $@ $_isi_snaps }
    fi
  fi
}

(( $+functions[_isi_classic_snapshot_scheds] )) ||
_isi_classic_snapshot_scheds() {
  _isi_snap_scheds=(
    $(/usr/bin/isi_classic snapshot schedule list | /usr/bin/awk '{print $2}')
  )
  local cmd=${words[1]}
  if [[ $cmd == delete || $cmd == remove || $cmd == rm || $cmd == ls || $cmd == list ]]; then
    if (( CURRENT > 1)); then
      _tags values && { compadd $@ $_isi_snap_scheds }
    fi
  else
    if (( CURRENT == 2 )); then
      _tags values && { compadd $@ $_isi_snap_scheds }
    fi
  fi
}
