// Shared types used by apps/api and apps/web.

/** Standard API envelope (matches KIC convention: { data } on success, { error } on failure). */
export type ApiResponse<T> = { data: T; error?: never } | { data?: never; error: string };

export type Role = 'admin' | 'viewer' | 'allviewer' | 'noexport';
export type AccessRow = { email: string; role: Role; grp: string | null; codes: string[] | null };

export type Me = {
  identified: boolean; email: string | null; admin: boolean; all: boolean;
  canExport: boolean; known: boolean; groups: string[];
};

export type Lead = {
  id: string; first: string; last: string; country: string; nat: string; dob: string | null;
  phone: string | null; email: string | null; promo: string; points: number | null; prefix: string;
  group: string; acq: string | null; region: string; contact: string; sm: string;
};

/** Sentinel "group" meaning full access to every campaign group (allviewer). */
export const ALL_TOKEN = '*ALL*';
