import type { Database } from "./database.types.js";

/**
 * Utility type to remove null from a type
 */
export type RemoveNull<T> = T extends null ? never : T;

/**
 * Utility type to remove null from all properties of an object type
 */
export type RemoveNullFromObject<T, K extends keyof T = keyof T> = {
  [L in keyof T]: L extends K ? RemoveNull<T[L]> : T[L];
};

/**
 * Helper type to extract table types from Database
 */
export type Tables<TableName extends keyof Database["public"]["Tables"]> =
  Database["public"]["Tables"][TableName]["Row"];

/**
 * Helper type to extract insert types from Database
 */
export type TablesInsert<TableName extends keyof Database["public"]["Tables"]> =
  Database["public"]["Tables"][TableName]["Insert"];

/**
 * Helper type to extract update types from Database
 */
export type TablesUpdate<TableName extends keyof Database["public"]["Tables"]> =
  Database["public"]["Tables"][TableName]["Update"];
