#!/usr/bin/env bash
# lp-shop-rollback.sh — reverse lp-shop-migration.sh
# Re-grants the legacy EZShop + Kiranhart perms and clears ExcellentShop nodes.

set -euo pipefail

LP="rcon-cli lp"

run() {
    echo "+ $*" >&2
    $LP "$@" >/dev/null
}

# ---- Re-grant legacy ----
run group default permission set ezshop.use true
run group default permission set auctionhouse.use true
run group default permission set auctionhouse.list true
run group default permission set auctionhouse.bid true
run group staff   permission set auctionhouse.moderator true

# ---- Drop ExcellentShop nodes ----
for node in \
    excellentshop.shop.use \
    excellentshop.shop.buy.virtual \
    excellentshop.shop.sell.virtual \
    excellentshop.shop.sellall \
    excellentshop.shop.sellhand \
    excellentshop.shop.sellhandall \
    excellentshop.auction.use \
    excellentshop.auction.list \
    excellentshop.auction.bid \
    excellentshop.auction.buy \
    excellentshop.auction.cancel \
    excellentshop.auction.expire.collect \
    excellentshop.auction.sold.collect \
    coinsengine.balance \
    coinsengine.pay \
    coinsengine.top
do
    $LP group default permission unset "$node" 2>/dev/null || true
done

for node in excellentshop.auction.admin excellentshop.shop.admin coinsengine.admin; do
    $LP group staff permission unset "$node" 2>/dev/null || true
done

echo "lp-shop-rollback: done."
