import { nullableStringValidator } from "./stringValidator"

import type { ZodObject, ZodRawShape } from "zod"

export function nullableArrayObjectValidator<T extends ZodRawShape>(
  schema: ZodObject<T>
) {
  return schema
    .array()
    .nullish()
    .transform((arr) => (arr ? arr.filter(Boolean) : []))
}

export const nullableArrayStringValidator = nullableStringValidator
  .array()
  .nullish()
  .transform((arr) => (arr ? arr.filter(Boolean) : []))
