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

import * as z from "zod";
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 { SDKValidationError } from "../errors/sdkvalidationerror.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$inboundSchema:
  z.ZodNativeEnum<typeof PublicAuthCodeGrantRequestBodyGrantType> = z
    .nativeEnum(PublicAuthCodeGrantRequestBodyGrantType);

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

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace PublicAuthCodeGrantRequestBodyGrantType$ {
  /** @deprecated use `PublicAuthCodeGrantRequestBodyGrantType$inboundSchema` instead. */
  export const inboundSchema =
    PublicAuthCodeGrantRequestBodyGrantType$inboundSchema;
  /** @deprecated use `PublicAuthCodeGrantRequestBodyGrantType$outboundSchema` instead. */
  export const outboundSchema =
    PublicAuthCodeGrantRequestBodyGrantType$outboundSchema;
}

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

/** @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",
  });
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace PublicAuthCodeGrantRequestBody$ {
  /** @deprecated use `PublicAuthCodeGrantRequestBody$inboundSchema` instead. */
  export const inboundSchema = PublicAuthCodeGrantRequestBody$inboundSchema;
  /** @deprecated use `PublicAuthCodeGrantRequestBody$outboundSchema` instead. */
  export const outboundSchema = PublicAuthCodeGrantRequestBody$outboundSchema;
  /** @deprecated use `PublicAuthCodeGrantRequestBody$Outbound` instead. */
  export type Outbound = PublicAuthCodeGrantRequestBody$Outbound;
}

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

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