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

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

/**
 * The status of this update.
 *
 * @remarks
 *
 * - available - This release is available
 * - downloading - This release is downloading
 * - downloaded - This release has been downloaded
 * - installing - This release is installing
 * - tonight - This release will be installed tonight
 * - skipped - This release has been skipped
 * - error - This release has an error
 * - notify - This release is only notifying it is available (typically because it cannot be installed on this setup)
 * - done - This release is complete
 */
export enum GetUpdatesStatusState {
  Available = "available",
  Downloading = "downloading",
  Downloaded = "downloaded",
  Installing = "installing",
  Tonight = "tonight",
  Skipped = "skipped",
  Error = "error",
  Notify = "notify",
  Done = "done",
}

export type Release = {
  /**
   * A list of what has been added in this version
   */
  added?: string | undefined;
  /**
   * The URL of where this update is available
   */
  downloadURL?: string | undefined;
  /**
   * A list of what has been fixed in this version
   */
  fixed?: string | undefined;
  /**
   * The URL key of the update
   */
  key?: string | undefined;
  /**
   * The status of this update.
   *
   * @remarks
   *
   * - available - This release is available
   * - downloading - This release is downloading
   * - downloaded - This release has been downloaded
   * - installing - This release is installing
   * - tonight - This release will be installed tonight
   * - skipped - This release has been skipped
   * - error - This release has an error
   * - notify - This release is only notifying it is available (typically because it cannot be installed on this setup)
   * - done - This release is complete
   */
  state?: GetUpdatesStatusState | undefined;
  /**
   * The version available
   */
  version?: string | undefined;
};

export type GetUpdatesStatusMediaContainer = {
  /**
   * The version of the updater (currently `1`)
   */
  autoUpdateVersion?: number | undefined;
  /**
   * Indicates whether this install can be updated through these endpoints (typically only on MacOS and Windows)
   */
  canInstall?: boolean | undefined;
  /**
   * The last time a check for updates was performed
   */
  checkedAt?: number | undefined;
  /**
   * The URL where the update is available
   */
  downloadURL?: string | undefined;
  release?: Array<Release> | undefined;
  /**
   * The current error code (`0` means no error)
   */
  status?: number | undefined;
};

/**
 * OK
 */
export type GetUpdatesStatusResponseBody = {
  mediaContainer?: GetUpdatesStatusMediaContainer | undefined;
};

export type GetUpdatesStatusResponse = {
  /**
   * HTTP response content type for this operation
   */
  contentType: string;
  /**
   * HTTP response status code for this operation
   */
  statusCode: number;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse: Response;
  /**
   * OK
   */
  object?: GetUpdatesStatusResponseBody | undefined;
};

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

/** @internal */
export const Release$inboundSchema: z.ZodType<Release, z.ZodTypeDef, unknown> =
  z.object({
    added: z.string().optional(),
    downloadURL: z.string().optional(),
    fixed: z.string().optional(),
    key: z.string().optional(),
    state: GetUpdatesStatusState$inboundSchema.optional(),
    version: z.string().optional(),
  });

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

/** @internal */
export const GetUpdatesStatusMediaContainer$inboundSchema: z.ZodType<
  GetUpdatesStatusMediaContainer,
  z.ZodTypeDef,
  unknown
> = z.object({
  autoUpdateVersion: z.number().int().optional(),
  canInstall: z.boolean().optional(),
  checkedAt: z.number().int().optional(),
  downloadURL: z.string().optional(),
  Release: z.array(z.lazy(() => Release$inboundSchema)).optional(),
  status: z.number().int().optional(),
}).transform((v) => {
  return remap$(v, {
    "Release": "release",
  });
});

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

/** @internal */
export const GetUpdatesStatusResponseBody$inboundSchema: z.ZodType<
  GetUpdatesStatusResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  MediaContainer: z.lazy(() => GetUpdatesStatusMediaContainer$inboundSchema)
    .optional(),
}).transform((v) => {
  return remap$(v, {
    "MediaContainer": "mediaContainer",
  });
});

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

/** @internal */
export const GetUpdatesStatusResponse$inboundSchema: z.ZodType<
  GetUpdatesStatusResponse,
  z.ZodTypeDef,
  unknown
> = z.object({
  ContentType: z.string(),
  StatusCode: z.number().int(),
  RawResponse: z.instanceof(Response),
  object: z.lazy(() => GetUpdatesStatusResponseBody$inboundSchema).optional(),
}).transform((v) => {
  return remap$(v, {
    "ContentType": "contentType",
    "StatusCode": "statusCode",
    "RawResponse": "rawResponse",
  });
});

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