// src/utils/objectUtils.ts

/**
 * Creates a new object by omitting specified keys from a source object.
 * This is a generic utility function similar to what's found in libraries like Lodash.
 * @param obj The source object.
 * @param keys An array of keys to omit from the new object.
 * @returns A new object without the specified keys.
 */
export function omit<T extends object, K extends keyof T>(obj: T, keysToOmit: K[]): Omit<T, K> {
  // Using a Set for the keys to omit provides a faster lookup (O(1) on average)
  // compared to Array.prototype.includes() which is O(n).
  const keysToOmitSet = new Set(keysToOmit);
  const newObj = {} as Omit<T, K>;

  // Iterate over the object's own enumerable properties.
  for (const key in obj) {
    if (Object.prototype.hasOwnProperty.call(obj, key) && !keysToOmitSet.has(key as keyof T as K)) {
      // If the key is not in the omit set, add it to the new object.
      (newObj as Record<string, unknown>)[key] = obj[key];
    }
  }

  return newObj;
}
