import type { PeqEqUi } from "./types"; export type ShareApiAction = "create" | "query" | "accept" | "list" | "delete"; export function resolveShareApiMessage( action: ShareApiAction, res: { code: number; msg?: string }, eqUi: PeqEqUi, ): string { if (res.code === 200) return ""; if (action === "list") { return eqUi.mySharesLoadFail ?? "Failed to load share list"; } if (action === "delete") { if (res.code === 0) { return eqUi.mySharesDeleteFail ?? "Failed to delete share code"; } if (res.code === 400) { return eqUi.shareInvalidParams ?? eqUi.mySharesDeleteFail ?? "Invalid request"; } if (res.code === 500) { return eqUi.shareSystemError ?? eqUi.mySharesDeleteFail ?? "System error"; } return eqUi.mySharesDeleteFail ?? "Failed to delete share code"; } if (res.code === 0) { if (action === "create") { return eqUi.shareActiveExists ?? eqUi.shareCreateFail ?? "Failed to generate share code"; } return eqUi.importCodeNotFound ?? "Share code not found or expired"; } if (res.code === 400) { return eqUi.shareInvalidParams ?? eqUi.shareCreateFail ?? "Invalid request"; } if (res.code === 500) { return eqUi.shareSystemError ?? eqUi.shareCreateFail ?? "System error"; } if (action === "create") { return eqUi.shareCreateFail ?? "Failed to generate share code"; } if (action === "accept") { return eqUi.importFail ?? eqUi.importCodeNotFound ?? "Failed to import EQ"; } return eqUi.importCodeNotFound ?? "Share code not found or expired"; }