/*
 * 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 { ClosedEnum } from "../../types/enums.js";

/**
 * The grant type. This value must be set to "authorization_code".
 */
export const PublicAuthCodeGrantRequestBodyGrantType = {
  AuthorizationCode: "authorization_code",
} as const;
/**
 * The grant type. This value must be set to "authorization_code".
 */
export type PublicAuthCodeGrantRequestBodyGrantType = ClosedEnum<
  typeof PublicAuthCodeGrantRequestBodyGrantType
>;

/**
 * This grant uses Proof Key for Code Exchange (PKCE) to authenticate securely without requiring a client secret.
 */
export type PublicAuthCodeGrantRequestBody = {
  /**
   * The grant type. This value must be set to "authorization_code".
   */
  grantType?: PublicAuthCodeGrantRequestBodyGrantType | undefined;
  /**
   * The client ID of the application.
   */
  clientId: string;
  /**
   * The authorization code supplied to the callback.
   */
  code: string;
  /**
   * The code verifier used to authenticate the request. This value is generated by the client and must be included in the request.
   */
  codeVerifier: string;
};

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

/** @internal */
export type PublicAuthCodeGrantRequestBody$Outbound = {
  grant_type: string;
  client_id: string;
  code: string;
  code_verifier: string;
};

/** @internal */
export const PublicAuthCodeGrantRequestBody$outboundSchema: z.ZodType<
  PublicAuthCodeGrantRequestBody$Outbound,
  z.ZodTypeDef,
  PublicAuthCodeGrantRequestBody
> = z.object({
  grantType: PublicAuthCodeGrantRequestBodyGrantType$outboundSchema.default(
    "authorization_code",
  ),
  clientId: z.string(),
  code: z.string(),
  codeVerifier: z.string(),
}).transform((v) => {
  return remap$(v, {
    grantType: "grant_type",
    clientId: "client_id",
    codeVerifier: "code_verifier",
  });
});

export function publicAuthCodeGrantRequestBodyToJSON(
  publicAuthCodeGrantRequestBody: PublicAuthCodeGrantRequestBody,
): string {
  return JSON.stringify(
    PublicAuthCodeGrantRequestBody$outboundSchema.parse(
      publicAuthCodeGrantRequestBody,
    ),
  );
}
