/*
 * 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";
import { VcrImageLayer, VcrImageLayer$inboundSchema } from "./vcrimagelayer.js";

/**
 * Whether the manifest is a multi-platform image index, a single-platform image manifest or an attestation.
 */
export const VcrImageDetailKind = {
  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 VcrImageDetailKind = ClosedEnum<typeof VcrImageDetailKind>;

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

/**
 * A single image with its tags, status and resolved Dockerfile layer history.
 */
export type VcrImageDetail = {
  layers: Array<VcrImageLayer>;
  /**
   * Tags pointing at this image's manifest.
   */
  tags: Array<string>;
  /**
   * Internal identifier of the image.
   */
  id: string;
  /**
   * Identifier of the repository the image belongs to.
   */
  repositoryId: string;
  /**
   * SHA-256 digest of the image manifest.
   */
  manifestDigest: string;
  /**
   * Whether the manifest is a multi-platform image index, a single-platform image manifest or an attestation.
   */
  kind: VcrImageDetailKind;
  /**
   * 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;
  /**
   * Total size in bytes of the image's resources (manifest, config and layer blobs) stored by the registry.
   */
  sizeInBytes: number;
  /**
   * VHS-readiness status, or `null` for a multi-platform index.
   */
  status: VcrImageDetailStatus | null;
  /**
   * ISO 8601 timestamp of when the image was created.
   */
  createdAt: string;
};

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

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

/** @internal */
export const VcrImageDetail$inboundSchema: z.ZodType<
  VcrImageDetail,
  z.ZodTypeDef,
  unknown
> = z.object({
  layers: z.array(VcrImageLayer$inboundSchema),
  tags: z.array(types.string()),
  id: types.string(),
  repositoryId: types.string(),
  manifestDigest: types.string(),
  kind: VcrImageDetailKind$inboundSchema,
  platform: types.optional(types.string()),
  arch: types.optional(types.string()),
  pushedBy: types.optional(types.string()),
  sizeInBytes: types.number(),
  status: types.nullable(VcrImageDetailStatus$inboundSchema),
  createdAt: types.string(),
});

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