/*
 * 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 { 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";

export const UpdateVersionAction = {
  Promote: "promote",
  Restore: "restore",
  Discard: "discard",
} as const;
export type UpdateVersionAction = ClosedEnum<typeof UpdateVersionAction>;

export type UpdateVersionRequestBody = {
  id: string;
  action: UpdateVersionAction;
  name?: string | undefined;
};

export type UpdateVersionRequest = {
  projectId: string;
  /**
   * The Team identifier to perform the request on behalf of.
   */
  teamId?: string | undefined;
  /**
   * The Team slug to perform the request on behalf of.
   */
  slug?: string | undefined;
  requestBody?: UpdateVersionRequestBody | undefined;
};

export type UpdateVersionVersion = {
  /**
   * The unique identifier for the version.
   */
  id: string;
  /**
   * The key of the version. The key may be duplicated across versions if the contents are the same as a different version.
   */
  key: string;
  lastModified: number;
  createdBy: string;
  /**
   * Optional name for the version. If not provided, defaults to an ISO timestamp string.
   */
  name?: string | undefined;
  /**
   * Whether this version has not been promoted to production yet and is not serving end users.
   */
  isStaging?: boolean | undefined;
  /**
   * Whether this version is currently live in production.
   */
  isLive?: boolean | undefined;
  /**
   * The number of redirects in this version.
   */
  redirectCount?: number | undefined;
  /**
   * The staging link for previewing redirects in this version.
   */
  alias?: string | undefined;
};

export type UpdateVersionResponseBody = {
  version: UpdateVersionVersion;
};

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

/** @internal */
export type UpdateVersionRequestBody$Outbound = {
  id: string;
  action: string;
  name?: string | undefined;
};

/** @internal */
export const UpdateVersionRequestBody$outboundSchema: z.ZodType<
  UpdateVersionRequestBody$Outbound,
  z.ZodTypeDef,
  UpdateVersionRequestBody
> = z.object({
  id: z.string(),
  action: UpdateVersionAction$outboundSchema,
  name: z.string().optional(),
});

export function updateVersionRequestBodyToJSON(
  updateVersionRequestBody: UpdateVersionRequestBody,
): string {
  return JSON.stringify(
    UpdateVersionRequestBody$outboundSchema.parse(updateVersionRequestBody),
  );
}

/** @internal */
export type UpdateVersionRequest$Outbound = {
  projectId: string;
  teamId?: string | undefined;
  slug?: string | undefined;
  RequestBody?: UpdateVersionRequestBody$Outbound | undefined;
};

/** @internal */
export const UpdateVersionRequest$outboundSchema: z.ZodType<
  UpdateVersionRequest$Outbound,
  z.ZodTypeDef,
  UpdateVersionRequest
> = z.object({
  projectId: z.string(),
  teamId: z.string().optional(),
  slug: z.string().optional(),
  requestBody: z.lazy(() => UpdateVersionRequestBody$outboundSchema).optional(),
}).transform((v) => {
  return remap$(v, {
    requestBody: "RequestBody",
  });
});

export function updateVersionRequestToJSON(
  updateVersionRequest: UpdateVersionRequest,
): string {
  return JSON.stringify(
    UpdateVersionRequest$outboundSchema.parse(updateVersionRequest),
  );
}

/** @internal */
export const UpdateVersionVersion$inboundSchema: z.ZodType<
  UpdateVersionVersion,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: types.string(),
  key: types.string(),
  lastModified: types.number(),
  createdBy: types.string(),
  name: types.optional(types.string()),
  isStaging: types.optional(types.boolean()),
  isLive: types.optional(types.boolean()),
  redirectCount: types.optional(types.number()),
  alias: types.optional(types.string()),
});

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

/** @internal */
export const UpdateVersionResponseBody$inboundSchema: z.ZodType<
  UpdateVersionResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  version: z.lazy(() => UpdateVersionVersion$inboundSchema),
});

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