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

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

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

COUNT=$(psql -U postgres ${ACCOUNT_DB_NAME} -c "COPY (WITH t1 AS (SELECT DISTINCT item_id FROM high_lottery WHERE item_id NOT IN (SELECT item_id FROM powerupitem) ORDER BY item_id) SELECT COUNT(item_id) FROM t1) TO STDOUT;")

if [ "${COUNT}" -ne 0 ]; then
    OUTPUT=$(psql -U postgres ${ACCOUNT_DB_NAME} -c "COPY (WITH t1 AS (SELECT DISTINCT item_id FROM high_lottery WHERE item_id NOT IN (SELECT item_id FROM powerupitem)) SELECT item_id FROM t1 ORDER BY item_id) TO '${output_filename}' CSV HEADER")

    if [ "${env}" == "0" ]; then
        ENV_TAG="(測試)"
    elif [ "${env}" == "1" ]; then
        ENV_TAG="(正式)"
    fi
    send_messages ERROR high_lottery_vs_powerupitem_item_id "${ENV_TAG} 高階煉金表上設定版本內未包含的道具ID品項"
fi
