import { itemDefinition } from "../definitions/items.js"; import { isLetterStack } from "./letters.js"; import { isPartiallyConsumed } from "./charges.js"; /** Whether this stack may be listed as a marketplace sell order. */ export function canSellOnMarketplace (stack, characterId = null) { void characterId; const def = itemDefinition(stack?.itemId); if (!def || !stack) { return false; } if (def.marketplaceSellable === false) { return false; } // Belt-and-suspenders: letters never list, even if a def flag is missing. if (isLetterStack(stack)) { return false; } // Buyers do not pick listings — partially used goods must stay off the CE. if (isPartiallyConsumed(stack)) { return false; } return true; } /** @throws {Error & { userFacing?: boolean }} */ export function assertMarketplaceSellable (stack, characterId = null) { if (canSellOnMarketplace(stack, characterId)) { return; } const def = itemDefinition(stack?.itemId); const error = new Error( def?.marketplaceSellBlockedReason ?? (isLetterStack(stack) ? "Letters cannot be sold on the marketplace." : (isPartiallyConsumed(stack) ? "Partially used items cannot be sold on the marketplace." : "That item cannot be sold on the marketplace.")) ); error.userFacing = true; throw error; }