import {
  ImageVaultAsset,
  InsertResponse,
} from "@/types/components/imageVaultImage"

export function insertResponseToImageVaultAsset(
  response: InsertResponse
): ImageVaultAsset {
  const alt = response.Metadata?.find((meta) =>
    meta.Name.includes("AltText_")
  )?.Value

  const caption = response.Metadata?.find((meta) =>
    meta.Name.includes("Title_")
  )?.Value

  return {
    url: response.MediaConversions[0].Url,
    id: response.Id,
    meta: {
      alt,
      caption,
    },
    title: response.Name,
    dimensions: {
      width: response.MediaConversions[0].Width,
      height: response.MediaConversions[0].Height,
      aspectRatio: response.MediaConversions[0].FormatAspectRatio,
    },
  }
}
