import { z } from "zod"

import { nullableStringValidator } from "@/utils/zod/stringValidator"

export const imageSizesSchema = z.object({
  large: nullableStringValidator,
  medium: nullableStringValidator,
  small: nullableStringValidator,
  tiny: nullableStringValidator,
})

export const imageMetaDataSchema = z.object({
  altText: nullableStringValidator,
  altText_En: nullableStringValidator,
  copyRight: nullableStringValidator,
  title: nullableStringValidator,
})

const DEFAULT_IMAGE_OBJ = {
  metaData: {
    altText: "Default image",
    altText_En: "Default image",
    copyRight: "Default image",
    title: "Default image",
  },
  imageSizes: {
    tiny: "https://placehold.co/1280x720",
    small: "https://placehold.co/1280x720",
    medium: "https://placehold.co/1280x720",
    large: "https://placehold.co/1280x720",
  },
}

export const imageSchema = z
  .object({
    imageSizes: imageSizesSchema,
    metaData: imageMetaDataSchema,
  })
  .nullish()
  .transform((val) => {
    if (!val) {
      return DEFAULT_IMAGE_OBJ
    }
    return val
  })
