#!/bin/bash
# info: suspend database
# options: USER DATABASE
#
# The function for suspending a certain user database.


#----------------------------------------------------------#
#                    Variable&Function                     #
#----------------------------------------------------------#

# Argument defenition
user=$1
database=$2

# Includes
source $VESTA/func/main.sh
source $VESTA/func/db.sh
source $VESTA/conf/vesta.conf


#----------------------------------------------------------#
#                    Verifications                         #
#----------------------------------------------------------#

check_args '2' "$#" 'USER DATABASE'
validate_format 'user' 'database'
is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'db' 'DB' "$database"
is_object_unsuspended 'db' 'DB' "$database"


#----------------------------------------------------------#
#                       Action                             #
#----------------------------------------------------------#

# Get database values
get_database_values

# Switching on db type
case $TYPE in
    mysql) suspend_mysql_database ;;
    pgsql) suspend_pgsql_database ;;
esac


#----------------------------------------------------------#
#                       Vesta                              #
#----------------------------------------------------------#

# Updating db value
update_object_value 'db' 'DB' "$database" '$SUSPENDED' 'yes'
increase_user_value "$user" '$SUSPENDED_DB'

# Logging
log_event "$OK" "$EVENT"

exit
