/*
 * 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 { smartUnion } from "../types/smartUnion.js";
import { Drive, Drive$inboundSchema } from "./drive.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

/**
 * Region where the drive is stored. Defaults to iad1.
 */
export const GetOrCreateDriveRegion = {
  Iad1: "iad1",
  Sfo1: "sfo1",
  Cle1: "cle1",
  Cdg1: "cdg1",
  Fra1: "fra1",
  Arn1: "arn1",
  Sin1: "sin1",
  Pdx1: "pdx1",
  Lhr1: "lhr1",
  Icn1: "icn1",
  Bom1: "bom1",
  Cpt1: "cpt1",
  Dub1: "dub1",
  Gru1: "gru1",
  Hkg1: "hkg1",
  Syd1: "syd1",
  Yul1: "yul1",
  Hnd1: "hnd1",
  Kix1: "kix1",
} as const;
/**
 * Region where the drive is stored. Defaults to iad1.
 */
export type GetOrCreateDriveRegion = ClosedEnum<typeof GetOrCreateDriveRegion>;

export type GetOrCreateDriveRequestBody = {
  /**
   * The project ID or name to associate the drive with. Required unless using a Vercel OIDC token scoped to a project.
   */
  projectId?: string | undefined;
  /**
   * Maximum drive size in bytes. Defaults to 1 TiB when omitted (1 GiB for Hobby). The maximum quota is 16 TiB. Request a quota above 16 TiB at https://vercel.com/help.
   */
  maxSizeBytes?: number | undefined;
  /**
   * Region where the drive is stored. Defaults to iad1.
   */
  region?: GetOrCreateDriveRegion | undefined;
};

export type GetOrCreateDriveRequest = {
  /**
   * Name for the drive. Must be unique per project and URL-safe (alphanumeric, hyphens, underscores).
   */
  name: 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?: GetOrCreateDriveRequestBody | undefined;
};

export type GetOrCreateDriveSandboxesResponseBody = {
  /**
   * This object contains information related to a Vercel Sandbox Drive.
   */
  drive: Drive;
};

export type GetOrCreateDriveResponseBody = {
  /**
   * This object contains information related to a Vercel Sandbox Drive.
   */
  drive: Drive;
};

export type GetOrCreateDriveResponse =
  | GetOrCreateDriveResponseBody
  | GetOrCreateDriveSandboxesResponseBody;

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

/** @internal */
export type GetOrCreateDriveRequestBody$Outbound = {
  projectId?: string | undefined;
  maxSizeBytes?: number | undefined;
  region: string;
};

/** @internal */
export const GetOrCreateDriveRequestBody$outboundSchema: z.ZodType<
  GetOrCreateDriveRequestBody$Outbound,
  z.ZodTypeDef,
  GetOrCreateDriveRequestBody
> = z.object({
  projectId: z.string().optional(),
  maxSizeBytes: z.number().int().optional(),
  region: GetOrCreateDriveRegion$outboundSchema.default("iad1"),
});

export function getOrCreateDriveRequestBodyToJSON(
  getOrCreateDriveRequestBody: GetOrCreateDriveRequestBody,
): string {
  return JSON.stringify(
    GetOrCreateDriveRequestBody$outboundSchema.parse(
      getOrCreateDriveRequestBody,
    ),
  );
}

/** @internal */
export type GetOrCreateDriveRequest$Outbound = {
  name: string;
  teamId?: string | undefined;
  slug?: string | undefined;
  RequestBody?: GetOrCreateDriveRequestBody$Outbound | undefined;
};

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

export function getOrCreateDriveRequestToJSON(
  getOrCreateDriveRequest: GetOrCreateDriveRequest,
): string {
  return JSON.stringify(
    GetOrCreateDriveRequest$outboundSchema.parse(getOrCreateDriveRequest),
  );
}

/** @internal */
export const GetOrCreateDriveSandboxesResponseBody$inboundSchema: z.ZodType<
  GetOrCreateDriveSandboxesResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  drive: Drive$inboundSchema,
});

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

/** @internal */
export const GetOrCreateDriveResponseBody$inboundSchema: z.ZodType<
  GetOrCreateDriveResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  drive: Drive$inboundSchema,
});

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

/** @internal */
export const GetOrCreateDriveResponse$inboundSchema: z.ZodType<
  GetOrCreateDriveResponse,
  z.ZodTypeDef,
  unknown
> = smartUnion([
  z.lazy(() => GetOrCreateDriveResponseBody$inboundSchema),
  z.lazy(() => GetOrCreateDriveSandboxesResponseBody$inboundSchema),
]);

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