/*
 * 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 {
  HttpApiDecodeError,
  HttpApiDecodeError$inboundSchema,
} from "./httpapidecodeerror.js";
import { SDKValidationError } from "./sdkvalidationerror.js";
import {
  TldNotSupported,
  TldNotSupported$inboundSchema,
} from "./tldnotsupported.js";

export type GetTldRequest = {
  tld: string;
  teamId?: string | undefined;
};

/**
 * There was something wrong with the request
 */
export type GetTldDomainsRegistrarResponseBody =
  | TldNotSupported
  | HttpApiDecodeError;

/**
 * Success
 */
export type GetTldResponseBody = {
  /**
   * The language codes that are supported for the TLD. The key is the language code, and the value is the name of the language.
   */
  supportedLanguageCodes: { [k: string]: string };
};

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

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

export function getTldRequestToJSON(getTldRequest: GetTldRequest): string {
  return JSON.stringify(GetTldRequest$outboundSchema.parse(getTldRequest));
}

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

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

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

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