/**
 * Module system types — describes the contract every Mailforge module must
 * implement to be discoverable by the loader and toggleable via
 * `modules.config.ts`.
 *
 * A module is a self-contained slice of Mailforge functionality (e.g. Sending,
 * Stats, Recipients). Each declares its identity, UI tab, API routes, DB
 * tables, and adapter requirements. The host (`src/app/page.tsx`) renders
 * only modules whose config flag is `true`.
 */

export type ModuleId =
  | 'briefing'
  | 'editor'
  | 'recipients'
  | 'sending'
  | 'scheduler'
  | 'stats'
  | 'heroImage'
  | 'spamCheck'
  | 'sectionTemplates'
  | 'triggerTemplates';

export type AdapterRequirement = 'crm' | 'send' | 'ai' | 'image-gen';

export interface ModuleManifest {
  /** Stable identifier — used in `modules.config.ts` and for route prefixes. */
  id: ModuleId;
  /** Human-readable label shown in UI tabs and admin lists. */
  label: string;
  /** One-line description for the Settings UI module list. */
  description: string;
  /**
   * Display order in the tab bar (lower = leftmost). Disabled modules don't
   * affect the positions of others — the visible tabs shift up.
   */
  tabPosition: number;
  /**
   * IDs of other modules this one depends on at runtime. If a dependency is
   * disabled, the loader logs a warning and disables this module too.
   * Example: `scheduler` depends on `sending` — without it, scheduling
   * produces no effect.
   */
  dependsOn?: ModuleId[];
  /**
   * Adapters this module calls at runtime. If a required adapter is missing
   * (no registration in `adapters.config.ts`), the loader disables the module
   * and surfaces a UI hint.
   */
  requiredAdapters?: AdapterRequirement[];
  /**
   * Tables this module owns. Used by build-time migration filtering in
   * Phase D — only tables of active modules end up in the generated
   * migration set.
   */
  tables?: string[];
  /**
   * Whether this module CAN be disabled. Some core modules (briefing, editor)
   * are mandatory because they're foundational. Default: true.
   */
  optional?: boolean;
}

/** The shape of `modules.config.ts`. */
export type ModulesConfig = Record<ModuleId, boolean>;
