import { z } from "zod"

import { linkRefsUnionSchema } from "../../pageLinks"

export const linkConnectionRefsSchema = z
  .object({
    linkConnection: z.object({
      edges: z.array(
        z.object({
          node: linkRefsUnionSchema,
        })
      ),
    }),
  })
  .transform((data) => {
    if (!data.linkConnection.edges.length) {
      return null
    }

    return data.linkConnection.edges[0].node.system
  })
