import { z } from "zod"

import * as pageLinks from "@/server/routers/contentstack/schemas/pageLinks"

import { imageSchema } from "./image"
import { imageContainerSchema } from "./imageContainer"

export const contentEmbedsSchema = z
  .discriminatedUnion("__typename", [
    imageContainerSchema,
    imageSchema,
    pageLinks.accountPageSchema,
    pageLinks.contentPageSchema,
    pageLinks.hotelPageSchema,
    pageLinks.loyaltyPageSchema,
  ])
  .transform((data) => {
    const link = pageLinks.transform(data)
    if (link) {
      return link
    }
    return data
  })
