package com.dunerealms.menus;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
/**
* Everything the menus need from the game backend (Jarvis). Menus never talk to Jarvis directly.
*
Every method defaults to "not connected", so a backend only overrides what it supports and the
* menu tells the player politely instead of faking data or touching money.
*
Rules for implementers (full detail in docs/BACKEND.md):
* money is minor units (1.00 DM = 100); futures may complete on any thread; there are NO confirm screens,
* so each mutating call must be idempotent and safe against a double click.
*/
public interface Backend {
/** Complete a future exceptionally with this to mean "this feature is not wired yet". */
final class Unavailable extends RuntimeException { public Unavailable() { super("not wired", null, false, false); } }
record Result(boolean ok, String message) {
public static Result yes(String m) { return new Result(true, m); }
public static Result no(String m) { return new Result(false, m); }
}
/** fareMinor: -1 unknown (no fare line shown), 0 free, >0 price. */
record World(String id, String name, String tagline, Material icon, int online, boolean up, long fareMinor) {}
record Listing(String id, String title, Material icon, String seller, long priceMinor, int quantity, Integer kitVersion, boolean purchasable) {}
record Page(List
items, boolean hasNext) {}
record Org(String name, String role, int members, long vaultMinor) {}
record Member(UUID id, String name, String role) {}
/** state is one of ACTIVE, AVAILABLE, DONE. */
record Mission(String id, String title, Material icon, String state, int percent, boolean claimable, String summary, Long revision) {}
record Spice(int carried, long guildQuote, long smugglerQuote, long pendingMinor) {}
/** roster has 8 entries; blank = empty slot. */
record War(String title, List roster, List status, boolean canLaunch) {}
record Decision(String id, String title, Material icon, String cost, String effect, boolean allowed) {}
record House(String id, String name, String motto, Material banner, int version) {}
/** Rihla account. reservedMinor = amount+tax locked by pending outgoing transfers. collectableMinor = incoming transfers waiting to be collected. */
record Account(String accountNo, long balanceMinor, long reservedMinor, long collectableMinor) {}
/** direction is "OUT" (you sent it, still pending, cancellable) or "IN" (waiting for you to collect). taxMinor is only set for OUT. */
record Transfer(long id, String direction, String counterparty, long amountMinor, long taxMinor, String when) {}
record Refit(boolean possible, String itemName, Material icon, List costs, String note) {}
private static CompletableFuture na() { return CompletableFuture.failedFuture(new Unavailable()); }
// ---- wallet / travel ----
default CompletableFuture balance(Player p) { return na(); }
default CompletableFuture> worlds(Player p) { return na(); }
default CompletableFuture book(Player p, String worldId) { return na(); }
// ---- exchange (tab is "buy" | "kits" | "mine") ----
default CompletableFuture listings(Player p, String tab, int page) { return na(); }
default CompletableFuture buy(Player p, Listing offer, int qty) { return na(); }
default CompletableFuture withdraw(Player p, Listing offer) { return na(); }
/** Lists the item in the player's main hand at the given unit price. */
default CompletableFuture sell(Player p, ItemStack expected, int slot, long priceMinor) { return na(); }
default CompletableFuture collectPurchases(Player p) { return na(); }
// ---- organisations (kind is "clan" | "company") ----
default CompletableFuture org(Player p, String kind) { return na(); }
default CompletableFuture> members(Player p, String kind) { return na(); }
/** action ids used by the menus: home, claims, vault, allies, wars, invite, transactions, roles, war-transport */
default CompletableFuture orgAction(Player p, String kind, String action) { return na(); }
// ---- missions ----
default CompletableFuture> missions(Player p) { return na(); }
default CompletableFuture missionAction(Player p, Mission mission, boolean claim) { return na(); }
// ---- spice (channel is "guild" | "smuggler") ----
default CompletableFuture spice(Player p) { return na(); }
default CompletableFuture sellSpice(Player p, String channel) { return na(); }
default CompletableFuture collectSpice(Player p) { return na(); }
// ---- war muster ----
default CompletableFuture war(Player p) { return na(); }
default CompletableFuture> warCandidates(Player p) { return na(); }
default CompletableFuture warAssign(Player p, int slot, UUID candidateOrNull) { return na(); }
default CompletableFuture warSave(Player p) { return na(); }
default CompletableFuture warLaunch(Player p) { return na(); }
// ---- politics / house / equipment ----
default CompletableFuture> decisions(Player p) { return na(); }
default CompletableFuture enact(Player p, String id) { return na(); }
default CompletableFuture> houses(Player p) { return na(); }
default CompletableFuture chooseHouse(Player p, House house) { return na(); }
default CompletableFuture refitQuote(Player p) { return na(); }
default CompletableFuture refit(Player p) { return na(); }
// ---- Rihla money transfer (Corrino Group). Used by the Bank screen and the ATM. ----
// Rules (docs/BACKEND.md): private account per user; sending creates a pending transfer that reserves
// amount + tax (1% up to and including 3,000 DM, 5% above, rounded UP to the next cent); the recipient
// receives the full amount and collects it in-game; cancelling releases the reservation.
default CompletableFuture bankAccount(Player p) { return na(); }
/** ATM, tab 1. The player taps bills and coins; the menu sends the total. Backend takes the cash and CREATES a new RIA ID worth that amount. */
record Issued(boolean ok, String message, String riaId) {}
default CompletableFuture atmCreateRia(Player p, long amountMinor) { return na(); }
/** ATM, tab 2. Look an RIA ID up so the menu can show the amount before payout. Return null/exceptional if unknown. */
record Voucher(String riaId, long amountMinor, String fromName) {}
default CompletableFuture atmLookup(Player p, String riaId) { return na(); }
/** ATM, tab 2. Pay the RIA ID out: toBank=false gives cash, toBank=true credits the player's bank account. One click, no confirmation. */
default CompletableFuture atmRedeem(Player p, String riaId, boolean toBank) { return na(); }
/** Cash withdrawal from the RIA account. The menu builds amountMinor from the bills and coins the player tapped.
* The backend debits the account and gives the player that cash (however cash is represented), or returns Result.no (insufficient funds, inventory full...). */
default CompletableFuture bankWithdraw(Player p, long amountMinor) { return na(); }
default CompletableFuture> bankTransfers(Player p) { return na(); }
default CompletableFuture bankSend(Player p, UUID to, long amountMinor) { return na(); }
default CompletableFuture bankCancel(Player p, long transferId) { return na(); }
/** transferId -1 collects every incoming transfer. */
default CompletableFuture bankCollect(Player p, long transferId) { return na(); }
}