import type { ChatConfig } from '@genesislcap/foundation-ai';

/** Resolved cost-history settings from `chatConfig.costHistory`. */
export interface ResolvedCostHistoryConfig {
  /** When `true`, sessions are persisted automatically and history is shown. */
  enabled: boolean;
  /** Host label for the active session (e.g. project name). */
  title?: string;
  /** `localStorage` scope key; falls back to element `id` then `'default'`. */
  scope?: string;
  /** Show running session USD on the Cost tab. Default: `true`. */
  showCost: boolean;
  /** Show cumulative session tokens on the Cost tab. Default: `true`. */
  showTokens: boolean;
  /** Live-session badge label on the Cost tab summary. */
  badgeLabel: string;
}

/** Resolve `chatConfig.costHistory` with defaults applied. */
export function resolveCostHistoryConfig(chatConfig: ChatConfig): ResolvedCostHistoryConfig {
  const cost = chatConfig.costHistory;

  return {
    enabled: cost?.enabled === true,
    title: cost?.title?.trim() || undefined,
    scope: cost?.scope?.trim() || undefined,
    showCost: cost?.showCost !== false,
    showTokens: cost?.showTokens !== false,
    badgeLabel: cost?.badgeLabel ?? 'Currently building',
  };
}
