import { z } from "zod"

import { nullableStringValidator } from "@/utils/zod/stringValidator"

import type { PaymentMethodEnum } from "@/constants/booking"

export const merchantInformationSchema = z.object({
  alternatePaymentOptions: z
    .record(z.string(), z.boolean())
    .transform((val) => {
      return Object.entries(val)
        .filter(([_, enabled]) => enabled)
        .map(([key]) => key)
        .filter((key): key is PaymentMethodEnum => !!key)
    }),
  cards: z.record(z.string(), z.boolean()).transform((val) => {
    return Object.entries(val)
      .filter(([_, enabled]) => enabled)
      .map(([key]) => key)
      .filter((key): key is PaymentMethodEnum => !!key)
  }),
  webMerchantId: nullableStringValidator,
})
