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

import * as z from "zod/v4-mini";
import { remap as remap$ } from "../../lib/primitives.js";
import { ClosedEnum } from "../../types/enums.js";

export const WebTokenRequestSubType = {
  User: "user",
  Organization: "organization",
} as const;
export type WebTokenRequestSubType = ClosedEnum<typeof WebTokenRequestSubType>;

export type WebTokenRequest = {
  grantType: "web";
  clientId: string;
  clientSecret: string;
  sessionToken: string;
  subType?: WebTokenRequestSubType | undefined;
  sub?: string | null | undefined;
  scope?: string | null | undefined;
};

/** @internal */
export const WebTokenRequestSubType$outboundSchema: z.ZodMiniEnum<
  typeof WebTokenRequestSubType
> = z.enum(WebTokenRequestSubType);

/** @internal */
export type WebTokenRequest$Outbound = {
  grant_type: "web";
  client_id: string;
  client_secret: string;
  session_token: string;
  sub_type: string;
  sub?: string | null | undefined;
  scope?: string | null | undefined;
};

/** @internal */
export const WebTokenRequest$outboundSchema: z.ZodMiniType<
  WebTokenRequest$Outbound,
  WebTokenRequest
> = z.pipe(
  z.object({
    grantType: z.literal("web"),
    clientId: z.string(),
    clientSecret: z.string(),
    sessionToken: z.string(),
    subType: z._default(WebTokenRequestSubType$outboundSchema, "user"),
    sub: z.optional(z.nullable(z.string())),
    scope: z.optional(z.nullable(z.string())),
  }),
  z.transform((v) => {
    return remap$(v, {
      grantType: "grant_type",
      clientId: "client_id",
      clientSecret: "client_secret",
      sessionToken: "session_token",
      subType: "sub_type",
    });
  }),
);

export function webTokenRequestToJSON(
  webTokenRequest: WebTokenRequest,
): string {
  return JSON.stringify(WebTokenRequest$outboundSchema.parse(webTokenRequest));
}
