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

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";

export type OAuth2Token = {
  accessToken: string;
  tokenType?: "Bearer" | undefined;
  expiresIn?: number | null | undefined;
  scope?: string | null | undefined;
  refreshToken?: string | null | undefined;
  expiresAt?: Date | null | undefined;
};

/** @internal */
export type OAuth2Token$Outbound = {
  access_token: string;
  token_type: "Bearer";
  expires_in?: number | null | undefined;
  scope?: string | null | undefined;
  refresh_token?: string | null | undefined;
  expires_at?: string | null | undefined;
};

/** @internal */
export const OAuth2Token$outboundSchema: z.ZodType<
  OAuth2Token$Outbound,
  OAuth2Token
> = z.object({
  accessToken: z.string(),
  tokenType: z.literal("Bearer").default("Bearer" as const),
  expiresIn: z.nullable(z.int()).optional(),
  scope: z.nullable(z.string()).optional(),
  refreshToken: z.nullable(z.string()).optional(),
  expiresAt: z.nullable(z.date().transform(v => v.toISOString())).optional(),
}).transform((v) => {
  return remap$(v, {
    accessToken: "access_token",
    tokenType: "token_type",
    expiresIn: "expires_in",
    refreshToken: "refresh_token",
    expiresAt: "expires_at",
  });
});

export function oAuth2TokenToJSON(oAuth2Token: OAuth2Token): string {
  return JSON.stringify(OAuth2Token$outboundSchema.parse(oAuth2Token));
}
