/* eslint-disable @typescript-eslint/no-explicit-any */

export function removeFalsyValues<T extends Record<string, any>>(
  obj: T,
  excludeKeys: (keyof T)[] = []
): Partial<T> {
  return Object.entries(obj).reduce((acc, [key, value]) => {
    if (value || excludeKeys.includes(key as keyof T)) {
      acc[key as keyof T] = value;
    }
    return acc;
  }, {} as Partial<T>);
}

export function delay(ms: number): Promise<void> {
  return new Promise((resolve) => setTimeout(resolve, ms));
}

export function delayRD(minMs: number, maxMs: number): Promise<void> {
  const time = Math.floor(Math.random() * (maxMs - minMs + 1)) + minMs;
  return delay(time);
}
