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

import * as z from "zod/v4-mini";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import {
  AuthorizeResponseOrganization,
  AuthorizeResponseOrganization$inboundSchema,
} from "../components/authorizeresponseorganization.js";
import {
  AuthorizeResponseUser,
  AuthorizeResponseUser$inboundSchema,
} from "../components/authorizeresponseuser.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

/**
 * Successful Response
 */
export type Oauth2AuthorizeResponseOauth2Authorize =
  | AuthorizeResponseUser
  | AuthorizeResponseOrganization;

/** @internal */
export const Oauth2AuthorizeResponseOauth2Authorize$inboundSchema:
  z.ZodMiniType<Oauth2AuthorizeResponseOauth2Authorize, unknown> = z.union([
    AuthorizeResponseUser$inboundSchema,
    AuthorizeResponseOrganization$inboundSchema,
  ]);

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