import { StartPageEnum } from "@/types/enums/startPage"
import type { System } from "@/types/requests/system"
import type { StartPageRefs } from "@/types/trpc/routers/contentstack/startPage"

export function getConnections({ start_page }: StartPageRefs) {
  const connections: System["system"][] = [start_page.system]

  if (start_page.blocks) {
    start_page.blocks.forEach((block) => {
      switch (block.__typename) {
        case StartPageEnum.ContentStack.blocks.FullWidthCampaign: {
          block.full_width_campaign.full_width_campaignConnection.edges.forEach(
            ({ node }) => {
              connections.push(node.system)
            }
          )
          break
        }
      }
    })
  }

  return connections
}
