export function simpleDeepCopy<T>(obj: T): T {
  return JSON.parse(JSON.stringify(obj));
}

export function deepCopy<T>(obj: T): T {
  if (obj === null || typeof obj !== 'object') {
    return obj;
  }

  if (obj instanceof Array) {
    const arrCopy = [] as unknown[];
    for (let i = 0; i < obj.length; i++) {
      arrCopy[i] = deepCopy(obj[i]);
    }
    return arrCopy as unknown as T;
  }

  if (obj instanceof Function) {
    return obj;
  }

  const objCopy = {} as { [key: string]: unknown };
  for (const key in obj) {
    // eslint-disable-next-line no-prototype-builtins
    if (obj.hasOwnProperty(key)) {
      objCopy[key] = deepCopy((obj as { [key: string]: unknown })[key]);
    }
  }

  return objCopy as T;
}
