// @ts-check
import { commandFailure } from "wimble/server";
import { inviteData } from "./data.js";
/** @param {{ args: string[], caller: { authorityId: string, id: string, name: string, computer: { id: string } } | null, owner: { authorityId: string, id: string, name: string, computer: { id: string } }, host: { database: D1Database } }} context */
export default async function codes({ args, caller, owner, host }) {
if (args.includes("--help")) return "Show your available invite codes.\n\nUsage: codes.run.js\n";
if (!caller) return commandFailure("authentication required\n");
if (caller.authorityId !== owner.authorityId || caller.id !== owner.id) return commandFailure("invite codes are private to their owner\n");
const { available } = await inviteData(host.database, owner.name);
return `${available.length ? available.join("\n") : "No invite codes available."}\n`;
}