// Central plugin registry.
//
// Each entry here represents a self-contained feature that could eventually
// be packaged and sold as a standalone add-on. The `enabled` flag is the
// single source of truth for whether that feature is active — nav links,
// pages, and API routes all check this instead of being unconditionally on.
//
// To ship a real plugin system later, each of these keys would become an
// installable package; for now, flipping `enabled` to false here is enough
// to fully retract a feature from the running app without deleting code.
//
// Kept free of server-only imports (like next/server) so it can be safely
// imported from client components (Sidebar, page components) as well as API
// routes — see lib/plugin-gate.ts for the server-only API route helper.
export type PluginKey =
  | "wallet"
  | "marketplace"
  | "leaderboard"
  | "crowdfunding"
  | "premium"
  | "admin"
  | "storyEffects"
  | "jobs"
  | "offers";

export type PluginDefinition = {
  key: PluginKey;
  name: string;
  description: string;
  enabled: boolean;
};

export const PLUGINS: Record<PluginKey, PluginDefinition> = {
  wallet: {
    key: "wallet",
    name: "Wallet",
    description: "$ virtual currency, deposits, withdrawals, and tipping.",
    enabled: true,
  },
  marketplace: {
    key: "marketplace",
    name: "Marketplace",
    description: "Buy and sell listings using.",
    enabled: true,
  },
  jobs: {
    key: "jobs",
    name: "Jobs",
    description: "Job adverts with salary, type and an application form.",
    enabled: true,
  },
  offers: {
    key: "offers",
    name: "Offers",
    description: "Discounts and deals — percent off, money off, buy X get Y.",
    enabled: true,
  },
  leaderboard: {
    key: "leaderboard",
    name: "Leaderboard",
    description: "Ranks users by followers, engagement, and posts.",
    enabled: true,
  },
  crowdfunding: {
    key: "crowdfunding",
    name: "Crowdfunding",
    description: "Campaigns that accept contributions.",
    enabled: true,
  },
  premium: {
    key: "premium",
    name: "Go Premium",
    description: "One-time purchase that grants a Premium badge.",
    enabled: true,
  },
  admin: {
    key: "admin",
    name: "Admin Panel",
    description: "Dashboard, user management, reports, and moderation.",
    enabled: true,
  },
  storyEffects: {
    key: "storyEffects",
    name: "Story Effects",
    description:
      "Rich story creation: font styles, text colors, background gradients, emoji stickers, freehand drawing, and music. Without this plugin, stories fall back to a basic photo + plain text editor.",
    enabled: true,
  },
};

export function isPluginEnabled(key: PluginKey): boolean {
  return PLUGINS[key]?.enabled ?? false;
}

export function listPlugins(): PluginDefinition[] {
  return Object.values(PLUGINS);
}
