#!/bin/bash
# info: unsuspend dns domain record
# options: USER DOMAIN ID [RESTART]
#
# The function unsuspends a certain domain record.


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

# Argument definition
user=$1
domain=$2
domain_idn=$2
id=$3
restart=$4

# Includes
source $HESTIA/func/main.sh
source $HESTIA/func/domain.sh
source $HESTIA/conf/hestia.conf

# Additional argument formatting
format_domain
format_domain_idn
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?


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

check_args '3' "$#" 'USER DOMAIN ID [RESTART]'
is_format_valid 'user' 'domain' 'id'
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_valid 'dns' 'DOMAIN' "$domain"
is_object_unsuspended 'dns' 'DOMAIN' "$domain"
is_object_valid "dns/$domain" 'ID' "$id"


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

update_object_value "dns/$domain" 'ID' "$id"  '$SUSPENDED' "no"

# Updating zone
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
    update_domain_serial
    update_domain_zone
fi


#----------------------------------------------------------#
#                       Hestia                             #
#----------------------------------------------------------#

# Logging
log_event "$OK" "$ARGUMENTS"

exit
