import { z } from "zod"

import { ContentEnum } from "@/types/enums/content"

// SysAsset is used for several different assets in ContentStack, such as images, pdf-files, etc.
// It is a generic asset type that can represent any file type.
// A lot of the fields are optional/nullable, hence the use of `.nullish()`.
// The properties of this schema should be handled inside the components that use it, fe. web/apps/scandic-web/components/JsonToHtml/renderOptions.tsx.
export const sysAssetSchema = z.object({
  __typename: z.literal(ContentEnum.blocks.SysAsset),
  content_type: z.string().nullish(),
  description: z.string().nullish(),
  dimension: z
    .object({
      height: z.number(),
      width: z.number(),
    })
    .nullish(),
  metadata: z.any(), // JSON
  // system for SysAssets is not the same type
  // as for all other types eventhough they have
  // the exact same structure, that's why systemSchema
  // is not used as that correlates to the
  // EntrySystemField type
  system: z
    .object({
      uid: z.string(),
    })
    .nullish(),
  title: z.string().nullish(),
  url: z.string().nullish(),
})

export const sysAssetRefsSchema = z.object({
  __typename: z.literal(ContentEnum.blocks.SysAsset),
})
