// Utility to remove empty values
export const removeEmptyValues = <T>(obj: T): T => {
    if (Array.isArray(obj)) {
      return obj
        .map((item) => removeEmptyValues(item))
        .filter(
          (item) =>
            !(
              item == null ||
              item === "" ||
              (typeof item === "object" &&
                !Array.isArray(item) &&
                Object.keys(item as object).length === 0)
            )
        ) as unknown as T;
    } else if (typeof obj === "object" && obj !== null) {
      return Object.fromEntries(
        Object.entries(obj)
          .map(([k, v]) => [k, removeEmptyValues(v)])
          .filter(
            ([, v]) =>
              !(
                v == null ||
                v === "" ||
                (typeof v === "object" &&
                  !Array.isArray(v) &&
                  Object.keys(v as object).length === 0)
              )
          )
      ) as T;
    }
    return obj;
  };
  