#!/usr/bin/env bash
# lp-shop-migration.sh — grant ExcellentShop + CoinsEngine perms to default group
#
# Adds the default-tier permissions players need to /shop, /sellall, /ah-list,
# and /ah-bid. Mirrors the perm surface that EZShop + Kiranhart AH gave for free.
#
# DOES NOT touch group prefixes/suffixes — those are operator-managed
# (feedback_lp_prefixes_locked.md). Only `permission set` calls.
#
# Run via:
#   ssh user@192.168.0.100 'docker exec -i minecraft-mc \
#       bash -s' < lp-shop-migration.sh
# or copy this into the container and run there.

set -euo pipefail

LP="rcon-cli lp"

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

# ---- ExcellentShop (Virtual Shop module) ----
run group default permission set excellentshop.shop.use true
run group default permission set excellentshop.shop.buy.virtual true
run group default permission set excellentshop.shop.sell.virtual true
run group default permission set excellentshop.shop.sellall true
run group default permission set excellentshop.shop.sellhand true
run group default permission set excellentshop.shop.sellhandall true

# ---- ExcellentShop (Auction House module) ----
run group default permission set excellentshop.auction.use true
run group default permission set excellentshop.auction.list true
run group default permission set excellentshop.auction.bid true
run group default permission set excellentshop.auction.buy true
run group default permission set excellentshop.auction.cancel true
run group default permission set excellentshop.auction.expire.collect true
run group default permission set excellentshop.auction.sold.collect true

# ---- CoinsEngine ----
run group default permission set coinsengine.balance true
run group default permission set coinsengine.pay true
run group default permission set coinsengine.top true

# ---- Operator/admin tier ----
# The 'staff' group inherits these for moderation parity with the old
# Kiranhart 'auctionhouse.moderator' node.
run group staff permission set excellentshop.auction.admin true
run group staff permission set excellentshop.shop.admin true
run group staff permission set coinsengine.admin true

# ---- Revoke legacy nodes (cleanup) ----
# These map to EZShop / Kiranhart and become dead weight after the swap.
# Wrapped in `|| true` because they may not exist on a fresh perms tree.
$LP group default permission unset ezshop.use 2>/dev/null || true
$LP group default permission unset auctionhouse.use 2>/dev/null || true
$LP group default permission unset auctionhouse.list 2>/dev/null || true
$LP group default permission unset auctionhouse.bid 2>/dev/null || true
$LP group staff   permission unset auctionhouse.moderator 2>/dev/null || true

echo "lp-shop-migration: done."
