#!/bin/bash
source $HOME/.gamerc

[ "$1" == "" ] && exec echo "Usage: $0 <Environment (TEST => 0, LIVE => 1)>"

env=$1
output_filename="/tmp/gacha_cointype2_monitor.log"

sudo rm -rf ${output_filename}

COUNT=$(psql -U postgres ${ACCOUNT_DB_NAME} -c "COPY (WITH t1 AS (SELECT id, sequence, set, type, item_id, item_num FROM bonus_activity_gacha WHERE item_id = 2 ORDER BY id, sequence, set, type, item_id, item_num) SELECT COUNT(*) FROM t1) TO STDOUT")

if [ "${COUNT}" -ne 0 ]; then
    OUTPUT=$(psql -U postgres ${ACCOUNT_DB_NAME} -c "COPY (SELECT id, sequence, set, type, item_id, item_num FROM bonus_activity_gacha WHERE item_id = 2 ORDER BY id, sequence, set, type, item_id, item_num) TO '${output_filename}' CSV HEADER")

    if [ "${env}" == "0" ]; then
        ENV_TAG="(測試)"
    elif [ "${env}" == "1" ]; then
        ENV_TAG="(正式)"
    fi
    send_messages ERROR gacha_cointype2 "${ENV_TAG} Bonus Activity Gacha 設定到給予付費鑽"
fi
