/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod/v3";
import { safeParse } from "../lib/schemas.js";
import { ClosedEnum } from "../types/enums.js";
import { Result as SafeParseResult } from "../types/fp.js";
import * as types from "../types/primitives.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

/**
 * Whether the manifest is a multi-platform image index, a single-platform image manifest or an attestation.
 */
export const VcrTagKind = {
  Attestation: "attestation",
  Index: "index",
  Manifest: "manifest",
} as const;
/**
 * Whether the manifest is a multi-platform image index, a single-platform image manifest or an attestation.
 */
export type VcrTagKind = ClosedEnum<typeof VcrTagKind>;

/**
 * VHS-readiness status, or `null` for a multi-platform index.
 */
export const VcrTagStatus = {
  Preparing: "preparing",
  Ready: "ready",
  Unoptimized: "unoptimized",
} as const;
/**
 * VHS-readiness status, or `null` for a multi-platform index.
 */
export type VcrTagStatus = ClosedEnum<typeof VcrTagStatus>;

/**
 * A tag pointing at an image in a Vercel Container Registry repository, enriched with the backing image's metadata and VHS-readiness status.
 */
export type VcrTag = {
  /**
   * The tag name.
   */
  tag: string;
  /**
   * SHA-256 digest of the image manifest the tag points at.
   */
  manifestDigest: string;
  /**
   * Internal identifier of the image the tag points at.
   */
  imageId: string;
  /**
   * Whether the manifest is a multi-platform image index, a single-platform image manifest or an attestation.
   */
  kind: VcrTagKind;
  /**
   * Operating system the manifest targets. Only present for single-platform manifests.
   */
  platform?: string | undefined;
  /**
   * CPU architecture the manifest targets. Only present for single-platform manifests.
   */
  arch?: string | undefined;
  /**
   * Identifier of the actor that pushed the image.
   */
  pushedBy?: string | undefined;
  /**
   * VHS-readiness status, or `null` for a multi-platform index.
   */
  status: VcrTagStatus | null;
  /**
   * Total size in bytes of the image's resources (manifest, config and layer blobs) stored by the registry.
   */
  sizeInBytes: number;
  /**
   * ISO 8601 timestamp of when the tag was created.
   */
  createdAt: string;
  /**
   * ISO 8601 timestamp of when the tag was last updated.
   */
  updatedAt: string;
};

/** @internal */
export const VcrTagKind$inboundSchema: z.ZodNativeEnum<typeof VcrTagKind> = z
  .nativeEnum(VcrTagKind);

/** @internal */
export const VcrTagStatus$inboundSchema: z.ZodNativeEnum<typeof VcrTagStatus> =
  z.nativeEnum(VcrTagStatus);

/** @internal */
export const VcrTag$inboundSchema: z.ZodType<VcrTag, z.ZodTypeDef, unknown> = z
  .object({
    tag: types.string(),
    manifestDigest: types.string(),
    imageId: types.string(),
    kind: VcrTagKind$inboundSchema,
    platform: types.optional(types.string()),
    arch: types.optional(types.string()),
    pushedBy: types.optional(types.string()),
    status: types.nullable(VcrTagStatus$inboundSchema),
    sizeInBytes: types.number(),
    createdAt: types.string(),
    updatedAt: types.string(),
  });

export function vcrTagFromJSON(
  jsonString: string,
): SafeParseResult<VcrTag, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => VcrTag$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'VcrTag' from JSON`,
  );
}
