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

/**
 * Field to sort drives by.
 */
export const ListDrivesQueryParamSortBy = {
  CreatedAt: "createdAt",
  UpdatedAt: "updatedAt",
  Name: "name",
} as const;
/**
 * Field to sort drives by.
 */
export type ListDrivesQueryParamSortBy = ClosedEnum<
  typeof ListDrivesQueryParamSortBy
>;

/**
 * Sort direction for results.
 */
export const ListDrivesQueryParamSortOrder = {
  Asc: "asc",
  Desc: "desc",
} as const;
/**
 * Sort direction for results.
 */
export type ListDrivesQueryParamSortOrder = ClosedEnum<
  typeof ListDrivesQueryParamSortOrder
>;

export type ListDrivesRequest = {
  /**
   * The project ID or name associated with the drives. Required unless using a Vercel OIDC token scoped to a project.
   */
  projectId?: string | undefined;
  /**
   * Maximum number of drives to return in the response. Used for pagination.
   */
  limit?: number | undefined;
  /**
   * Opaque pagination cursor from a previous response.
   */
  cursor?: string | undefined;
  /**
   * Field to sort drives by.
   */
  sortBy?: ListDrivesQueryParamSortBy | undefined;
  /**
   * Filter drives whose name starts with this prefix. Only valid when sortBy=name.
   */
  namePrefix?: string | undefined;
  /**
   * Sort direction for results.
   */
  sortOrder?: ListDrivesQueryParamSortOrder | undefined;
  /**
   * 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;
};

export type ListDrivesPagination = {
  count: number;
  next: string | null;
};

export type ListDrivesResponseBody = {
  drives: Array<Drive>;
  pagination: ListDrivesPagination;
};

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

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

/** @internal */
export type ListDrivesRequest$Outbound = {
  projectId?: string | undefined;
  limit: number;
  cursor?: string | undefined;
  sortBy: string;
  namePrefix?: string | undefined;
  sortOrder: string;
  teamId?: string | undefined;
  slug?: string | undefined;
};

/** @internal */
export const ListDrivesRequest$outboundSchema: z.ZodType<
  ListDrivesRequest$Outbound,
  z.ZodTypeDef,
  ListDrivesRequest
> = z.object({
  projectId: z.string().optional(),
  limit: z.number().default(20),
  cursor: z.string().optional(),
  sortBy: ListDrivesQueryParamSortBy$outboundSchema.default("createdAt"),
  namePrefix: z.string().optional(),
  sortOrder: ListDrivesQueryParamSortOrder$outboundSchema.default("desc"),
  teamId: z.string().optional(),
  slug: z.string().optional(),
});

export function listDrivesRequestToJSON(
  listDrivesRequest: ListDrivesRequest,
): string {
  return JSON.stringify(
    ListDrivesRequest$outboundSchema.parse(listDrivesRequest),
  );
}

/** @internal */
export const ListDrivesPagination$inboundSchema: z.ZodType<
  ListDrivesPagination,
  z.ZodTypeDef,
  unknown
> = z.object({
  count: types.number(),
  next: types.nullable(types.string()),
});

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

/** @internal */
export const ListDrivesResponseBody$inboundSchema: z.ZodType<
  ListDrivesResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  drives: z.array(Drive$inboundSchema),
  pagination: z.lazy(() => ListDrivesPagination$inboundSchema),
});

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