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

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

/**
 * Custom superset of RFC 8414 OAuth 2.0 Authorization Server Metadata.
 *
 * @remarks
 *
 * Stored at connector creation time (provided for HTTP connectors, discovered via .well-known for MCP).
 * Mirrors the shape of .well-known/oauth-authorization-server responses.
 */
export type ExtendedOAuthServerMetadata = {
  issuer: string;
  authorizationEndpoint: string;
  tokenEndpoint: string;
  registrationEndpoint?: string | null | undefined;
  scopesSupported?: Array<string> | null | undefined;
  responseTypesSupported?: Array<string> | undefined;
  responseModesSupported?: Array<string> | null | undefined;
  grantTypesSupported?: Array<string> | null | undefined;
  tokenEndpointAuthMethodsSupported?: Array<string> | null | undefined;
  tokenEndpointAuthSigningAlgValuesSupported?: Array<string> | null | undefined;
  serviceDocumentation?: string | null | undefined;
  uiLocalesSupported?: Array<string> | null | undefined;
  opPolicyUri?: string | null | undefined;
  opTosUri?: string | null | undefined;
  revocationEndpoint?: string | null | undefined;
  revocationEndpointAuthMethodsSupported?: Array<string> | null | undefined;
  revocationEndpointAuthSigningAlgValuesSupported?:
    | Array<string>
    | null
    | undefined;
  introspectionEndpoint?: string | null | undefined;
  introspectionEndpointAuthMethodsSupported?: Array<string> | null | undefined;
  introspectionEndpointAuthSigningAlgValuesSupported?:
    | Array<string>
    | null
    | undefined;
  codeChallengeMethodsSupported?: Array<string> | null | undefined;
  clientIdMetadataDocumentSupported?: boolean | null | undefined;
  xResourceUrl?: string | null | undefined;
};

/** @internal */
export type ExtendedOAuthServerMetadata$Outbound = {
  issuer: string;
  authorization_endpoint: string;
  token_endpoint: string;
  registration_endpoint?: string | null | undefined;
  scopes_supported?: Array<string> | null | undefined;
  response_types_supported?: Array<string> | undefined;
  response_modes_supported?: Array<string> | null | undefined;
  grant_types_supported?: Array<string> | null | undefined;
  token_endpoint_auth_methods_supported?: Array<string> | null | undefined;
  token_endpoint_auth_signing_alg_values_supported?:
    | Array<string>
    | null
    | undefined;
  service_documentation?: string | null | undefined;
  ui_locales_supported?: Array<string> | null | undefined;
  op_policy_uri?: string | null | undefined;
  op_tos_uri?: string | null | undefined;
  revocation_endpoint?: string | null | undefined;
  revocation_endpoint_auth_methods_supported?: Array<string> | null | undefined;
  revocation_endpoint_auth_signing_alg_values_supported?:
    | Array<string>
    | null
    | undefined;
  introspection_endpoint?: string | null | undefined;
  introspection_endpoint_auth_methods_supported?:
    | Array<string>
    | null
    | undefined;
  introspection_endpoint_auth_signing_alg_values_supported?:
    | Array<string>
    | null
    | undefined;
  code_challenge_methods_supported?: Array<string> | null | undefined;
  client_id_metadata_document_supported?: boolean | null | undefined;
  x_resource_url?: string | null | undefined;
};

/** @internal */
export const ExtendedOAuthServerMetadata$outboundSchema: z.ZodType<
  ExtendedOAuthServerMetadata$Outbound,
  ExtendedOAuthServerMetadata
> = z.object({
  issuer: z.string(),
  authorizationEndpoint: z.string(),
  tokenEndpoint: z.string(),
  registrationEndpoint: z.nullable(z.string()).optional(),
  scopesSupported: z.nullable(z.array(z.string())).optional(),
  responseTypesSupported: z.array(z.string()).optional(),
  responseModesSupported: z.nullable(z.array(z.string())).optional(),
  grantTypesSupported: z.nullable(z.array(z.string())).optional(),
  tokenEndpointAuthMethodsSupported: z.nullable(z.array(z.string())).optional(),
  tokenEndpointAuthSigningAlgValuesSupported: z.nullable(z.array(z.string()))
    .optional(),
  serviceDocumentation: z.nullable(z.string()).optional(),
  uiLocalesSupported: z.nullable(z.array(z.string())).optional(),
  opPolicyUri: z.nullable(z.string()).optional(),
  opTosUri: z.nullable(z.string()).optional(),
  revocationEndpoint: z.nullable(z.string()).optional(),
  revocationEndpointAuthMethodsSupported: z.nullable(z.array(z.string()))
    .optional(),
  revocationEndpointAuthSigningAlgValuesSupported: z.nullable(
    z.array(z.string()),
  ).optional(),
  introspectionEndpoint: z.nullable(z.string()).optional(),
  introspectionEndpointAuthMethodsSupported: z.nullable(z.array(z.string()))
    .optional(),
  introspectionEndpointAuthSigningAlgValuesSupported: z.nullable(
    z.array(z.string()),
  ).optional(),
  codeChallengeMethodsSupported: z.nullable(z.array(z.string())).optional(),
  clientIdMetadataDocumentSupported: z.nullable(z.boolean()).optional(),
  xResourceUrl: z.nullable(z.string()).optional(),
}).transform((v) => {
  return remap$(v, {
    authorizationEndpoint: "authorization_endpoint",
    tokenEndpoint: "token_endpoint",
    registrationEndpoint: "registration_endpoint",
    scopesSupported: "scopes_supported",
    responseTypesSupported: "response_types_supported",
    responseModesSupported: "response_modes_supported",
    grantTypesSupported: "grant_types_supported",
    tokenEndpointAuthMethodsSupported: "token_endpoint_auth_methods_supported",
    tokenEndpointAuthSigningAlgValuesSupported:
      "token_endpoint_auth_signing_alg_values_supported",
    serviceDocumentation: "service_documentation",
    uiLocalesSupported: "ui_locales_supported",
    opPolicyUri: "op_policy_uri",
    opTosUri: "op_tos_uri",
    revocationEndpoint: "revocation_endpoint",
    revocationEndpointAuthMethodsSupported:
      "revocation_endpoint_auth_methods_supported",
    revocationEndpointAuthSigningAlgValuesSupported:
      "revocation_endpoint_auth_signing_alg_values_supported",
    introspectionEndpoint: "introspection_endpoint",
    introspectionEndpointAuthMethodsSupported:
      "introspection_endpoint_auth_methods_supported",
    introspectionEndpointAuthSigningAlgValuesSupported:
      "introspection_endpoint_auth_signing_alg_values_supported",
    codeChallengeMethodsSupported: "code_challenge_methods_supported",
    clientIdMetadataDocumentSupported: "client_id_metadata_document_supported",
    xResourceUrl: "x_resource_url",
  });
});

export function extendedOAuthServerMetadataToJSON(
  extendedOAuthServerMetadata: ExtendedOAuthServerMetadata,
): string {
  return JSON.stringify(
    ExtendedOAuthServerMetadata$outboundSchema.parse(
      extendedOAuthServerMetadata,
    ),
  );
}
