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

import * as z from "zod/v3";
import { safeParse } from "../lib/schemas.js";
import { Result as SafeParseResult } from "../types/fp.js";
import * as types from "../types/primitives.js";
import { smartUnion } from "../types/smartUnion.js";
import {
  DomainNotRegistered,
  DomainNotRegistered$inboundSchema,
} from "./domainnotregistered.js";
import { Forbidden, Forbidden$inboundSchema } from "./forbidden.js";
import {
  HttpApiDecodeError,
  HttpApiDecodeError$inboundSchema,
} from "./httpapidecodeerror.js";
import {
  NotAuthorizedForScope,
  NotAuthorizedForScope$inboundSchema,
} from "./notauthorizedforscope.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

export type GetDomainAuthCodeRequest = {
  domain: string;
  teamId?: string | undefined;
};

/**
 * NotAuthorizedForScope
 */
export type GetDomainAuthCodeDomainsRegistrarResponseResponseBody =
  | (NotAuthorizedForScope & { code: "not_authorized_for_scope" })
  | Forbidden;

/**
 * There was something wrong with the request
 */
export type GetDomainAuthCodeDomainsRegistrarResponseBody =
  | DomainNotRegistered
  | HttpApiDecodeError;

/**
 * Success
 */
export type GetDomainAuthCodeResponseBody = {
  authCode: string;
};

/** @internal */
export type GetDomainAuthCodeRequest$Outbound = {
  domain: string;
  teamId?: string | undefined;
};

/** @internal */
export const GetDomainAuthCodeRequest$outboundSchema: z.ZodType<
  GetDomainAuthCodeRequest$Outbound,
  z.ZodTypeDef,
  GetDomainAuthCodeRequest
> = z.object({
  domain: z.string(),
  teamId: z.string().optional(),
});

export function getDomainAuthCodeRequestToJSON(
  getDomainAuthCodeRequest: GetDomainAuthCodeRequest,
): string {
  return JSON.stringify(
    GetDomainAuthCodeRequest$outboundSchema.parse(getDomainAuthCodeRequest),
  );
}

/** @internal */
export const GetDomainAuthCodeDomainsRegistrarResponseResponseBody$inboundSchema:
  z.ZodType<
    GetDomainAuthCodeDomainsRegistrarResponseResponseBody,
    z.ZodTypeDef,
    unknown
  > = z.union([
    NotAuthorizedForScope$inboundSchema.and(
      z.object({ code: z.literal("not_authorized_for_scope") }),
    ),
    Forbidden$inboundSchema,
  ]);

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

/** @internal */
export const GetDomainAuthCodeDomainsRegistrarResponseBody$inboundSchema:
  z.ZodType<
    GetDomainAuthCodeDomainsRegistrarResponseBody,
    z.ZodTypeDef,
    unknown
  > = smartUnion([
    DomainNotRegistered$inboundSchema,
    HttpApiDecodeError$inboundSchema,
  ]);

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

/** @internal */
export const GetDomainAuthCodeResponseBody$inboundSchema: z.ZodType<
  GetDomainAuthCodeResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  authCode: types.string(),
});

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