/** Reasons a credit transaction can be attributed to (drives icons/filters). */ export type CreditReason = | 'CONTENT_GEN' | 'PRODUCT_SCAN' | 'INLINE_FIX' | 'GAP_VERIFICATION' | 'KB_DOC' | 'ARTICLE_GEN' | 'ARTICLE_IMAGE' | 'VISIBILITY_SCAN'; /** A single ledger entry. `amount` is negative for consumption. */ export interface ICreditTransaction { id: string; user_id: string; amount: number; reason: CreditReason | string; ref_type: string | null; ref_id: string | null; balance_after: number; note: string | null; created_at: string; } /** Root-level response from GET /v2/credits/transactions. */ export interface ICreditTransactionsResponse { message: string; transactions: ICreditTransaction[]; total: number; success: boolean; page: number; total_pages: number; } /** Current credits snapshot (from the user payload or GET /v2/credits/balance). */ export interface ICreditBalance { balance?: number; granted?: number; used?: number; } export const EMPTY_CREDIT_HISTORY: ICreditTransactionsResponse = { message: '', transactions: [], total: 0, success: true, page: 1, total_pages: 1, }; /** Page-size bounds enforced by the API (1–100, default 25). */ export const CREDIT_HISTORY_PAGE_SIZE = 25; /** * Validates a YYYY-MM-DD value for the transactions endpoints. * Returns the value when well-formed, undefined otherwise. */ export function creditDateParam( value: string | null | undefined ): string | undefined { return value && /^\d{4}-\d{2}-\d{2}$/.test(value) ? value : undefined; }