import { z } from "zod"

import {
  accountPageSchema,
  collectionPageSchema,
  contentPageSchema,
  destinationCityPageSchema,
  destinationCountryPageSchema,
  destinationOverviewPageSchema,
  hotelPageSchema,
  loyaltyPageSchema,
  startPageSchema,
  transformPageLink,
} from "../pageLinks"
import { imageContainerSchema } from "./imageContainer"
import { sysAssetSchema } from "./sysAsset"

export const contentEmbedsSchema = z
  .discriminatedUnion("__typename", [
    imageContainerSchema,
    sysAssetSchema,
    accountPageSchema,
    collectionPageSchema,
    contentPageSchema,
    destinationCityPageSchema,
    destinationCountryPageSchema,
    destinationOverviewPageSchema,
    hotelPageSchema,
    loyaltyPageSchema,
    startPageSchema,
  ])
  .transform((data) => {
    const link = transformPageLink(data)
    if (link) {
      return link
    }
    return data
  })
