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

export type GetDomainPriceRequest = {
  domain: string;
  /**
   * The number of years to get the price for. If not provided, the minimum number of years for the TLD will be used.
   */
  years?: string | undefined;
  teamId?: string | undefined;
};

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

export type GetDomainPricePurchasePrice = number | string;

export type GetDomainPriceRenewalPrice = number | string;

export type GetDomainPriceTransferPrice = number | string;

/**
 * Success
 */
export type GetDomainPriceResponseBody = {
  years: number;
  purchasePrice: number | string;
  renewalPrice: number | string;
  transferPrice: number | string;
};

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

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

export function getDomainPriceRequestToJSON(
  getDomainPriceRequest: GetDomainPriceRequest,
): string {
  return JSON.stringify(
    GetDomainPriceRequest$outboundSchema.parse(getDomainPriceRequest),
  );
}

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

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

/** @internal */
export const GetDomainPricePurchasePrice$inboundSchema: z.ZodType<
  GetDomainPricePurchasePrice,
  z.ZodTypeDef,
  unknown
> = smartUnion([types.number(), types.string()]);

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

/** @internal */
export const GetDomainPriceRenewalPrice$inboundSchema: z.ZodType<
  GetDomainPriceRenewalPrice,
  z.ZodTypeDef,
  unknown
> = smartUnion([types.number(), types.string()]);

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

/** @internal */
export const GetDomainPriceTransferPrice$inboundSchema: z.ZodType<
  GetDomainPriceTransferPrice,
  z.ZodTypeDef,
  unknown
> = smartUnion([types.number(), types.string()]);

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

/** @internal */
export const GetDomainPriceResponseBody$inboundSchema: z.ZodType<
  GetDomainPriceResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  years: types.number(),
  purchasePrice: smartUnion([types.number(), types.string()]),
  renewalPrice: smartUnion([types.number(), types.string()]),
  transferPrice: smartUnion([types.number(), types.string()]),
});

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