/**
 * Type assertion helpers for TypeScript strict mode compatibility
 * These help bridge database types (null) with application types (undefined)
 */

export function nullToUndefined<T>(value: T | null): T | undefined {
  return value === null ? undefined : value;
}

export function convertNullsToUndefined<T extends Record<string, any>>(obj: T): { [K in keyof T]: T[K] extends (infer U | null) ? (U | undefined) : T[K] } {
  const result: any = {};
  for (const key in obj) {
    const value = obj[key];
    result[key] = value === null ? undefined : value;
  }
  return result;
}

// Type guard for checking if value is not null/undefined
export function isDefined<T>(value: T | null | undefined): value is T {
  return value !== null && value !== undefined;
}
