/*
 * 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";
import { SubType, SubType$outboundSchema } from "./subtype.js";

export const TokenEndpointAuthMethod = {
  ClientSecretBasic: "client_secret_basic",
  ClientSecretPost: "client_secret_post",
  None: "none",
} as const;
export type TokenEndpointAuthMethod = ClosedEnum<
  typeof TokenEndpointAuthMethod
>;

export const GrantTypes = {
  AuthorizationCode: "authorization_code",
  RefreshToken: "refresh_token",
} as const;
export type GrantTypes = ClosedEnum<typeof GrantTypes>;

export type OAuth2ClientConfiguration = {
  redirectUris: Array<string>;
  tokenEndpointAuthMethod?: TokenEndpointAuthMethod | undefined;
  grantTypes?: Array<GrantTypes> | undefined;
  responseTypes?: Array<string> | undefined;
  scope?: string | undefined;
  clientName: string;
  clientUri?: string | null | undefined;
  logoUri?: string | null | undefined;
  tosUri?: string | null | undefined;
  policyUri?: string | null | undefined;
  defaultSubType?: SubType | undefined;
};

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

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

/** @internal */
export type OAuth2ClientConfiguration$Outbound = {
  redirect_uris: Array<string>;
  token_endpoint_auth_method: string;
  grant_types?: Array<string> | undefined;
  response_types?: Array<string> | undefined;
  scope: string;
  client_name: string;
  client_uri?: string | null | undefined;
  logo_uri?: string | null | undefined;
  tos_uri?: string | null | undefined;
  policy_uri?: string | null | undefined;
  default_sub_type?: string | undefined;
};

/** @internal */
export const OAuth2ClientConfiguration$outboundSchema: z.ZodMiniType<
  OAuth2ClientConfiguration$Outbound,
  OAuth2ClientConfiguration
> = z.pipe(
  z.object({
    redirectUris: z.array(z.string()),
    tokenEndpointAuthMethod: z._default(
      TokenEndpointAuthMethod$outboundSchema,
      "client_secret_post",
    ),
    grantTypes: z.optional(z.array(GrantTypes$outboundSchema)),
    responseTypes: z.optional(z.array(z.string())),
    scope: z._default(
      z.string(),
      "openid profile email user:read user:write organizations:read organizations:write custom_fields:read custom_fields:write discounts:read discounts:write checkout_links:read checkout_links:write checkouts:read checkouts:write transactions:read transactions:write payouts:read payouts:write products:read products:write benefits:read benefits:write events:read events:write meters:read meters:write files:read files:write subscriptions:read subscriptions:write customers:read customers:write members:read members:write wallets:read wallets:write disputes:read disputes:write customer_meters:read customer_sessions:write member_sessions:write customer_seats:read customer_seats:write orders:read orders:write refunds:read refunds:write payments:read metrics:read metrics:write webhooks:read webhooks:write license_keys:read license_keys:write customer_portal:read customer_portal:write notifications:read notifications:write notification_recipients:read notification_recipients:write",
    ),
    clientName: z.string(),
    clientUri: z.optional(z.nullable(z.string())),
    logoUri: z.optional(z.nullable(z.string())),
    tosUri: z.optional(z.nullable(z.string())),
    policyUri: z.optional(z.nullable(z.string())),
    defaultSubType: z.optional(SubType$outboundSchema),
  }),
  z.transform((v) => {
    return remap$(v, {
      redirectUris: "redirect_uris",
      tokenEndpointAuthMethod: "token_endpoint_auth_method",
      grantTypes: "grant_types",
      responseTypes: "response_types",
      clientName: "client_name",
      clientUri: "client_uri",
      logoUri: "logo_uri",
      tosUri: "tos_uri",
      policyUri: "policy_uri",
      defaultSubType: "default_sub_type",
    });
  }),
);

export function oAuth2ClientConfigurationToJSON(
  oAuth2ClientConfiguration: OAuth2ClientConfiguration,
): string {
  return JSON.stringify(
    OAuth2ClientConfiguration$outboundSchema.parse(oAuth2ClientConfiguration),
  );
}
