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

import * as z from "zod/v3";
import { remap as remap$ } from "../lib/primitives.js";
import { safeParse } from "../lib/schemas.js";
import { ClosedEnum } from "../types/enums.js";
import { Result as SafeParseResult } from "../types/fp.js";
import * as types from "../types/primitives.js";
import { smartUnion } from "../types/smartUnion.js";
import {
  AdditionalContactInfoRequired,
  AdditionalContactInfoRequired$inboundSchema,
} from "./additionalcontactinforequired.js";
import {
  DomainNotAvailable,
  DomainNotAvailable$inboundSchema,
} from "./domainnotavailable.js";
import {
  DomainTooShort,
  DomainTooShort$inboundSchema,
} from "./domaintooshort.js";
import {
  ExpectedPriceMismatch,
  ExpectedPriceMismatch$inboundSchema,
} from "./expectedpricemismatch.js";
import { Forbidden, Forbidden$inboundSchema } from "./forbidden.js";
import {
  HttpApiDecodeError,
  HttpApiDecodeError$inboundSchema,
} from "./httpapidecodeerror.js";
import {
  InvalidAdditionalContactInfo,
  InvalidAdditionalContactInfo$inboundSchema,
} from "./invalidadditionalcontactinfo.js";
import {
  LanguageCodeRequired,
  LanguageCodeRequired$inboundSchema,
} from "./languagecoderequired.js";
import {
  NotAuthorizedForScope,
  NotAuthorizedForScope$inboundSchema,
} from "./notauthorizedforscope.js";
import {
  OrderTooExpensive,
  OrderTooExpensive$inboundSchema,
} from "./ordertooexpensive.js";
import { SDKValidationError } from "./sdkvalidationerror.js";
import {
  TldNotSupported,
  TldNotSupported$inboundSchema,
} from "./tldnotsupported.js";

export type Additional = {};

/**
 * The contact information for the domain. Some TLDs require additional contact information. Use the [Get contact info schema](https://vercel.com/docs/rest-api/reference/endpoints/domains-registrar/get-contact-info-schema) endpoint to retrieve the required fields.
 */
export type ContactInformation = {
  /**
   * a non empty string
   */
  firstName: string;
  /**
   * a non empty string
   */
  lastName: string;
  /**
   * A valid RFC 5322 email address
   */
  email: string;
  /**
   * A valid E.164 phone number
   */
  phone: string;
  /**
   * a non empty string
   */
  address1: string;
  /**
   * a non empty string
   */
  address2?: string | undefined;
  /**
   * a non empty string
   */
  city: string;
  /**
   * a non empty string
   */
  state: string;
  /**
   * a non empty string
   */
  zip: string;
  /**
   * A valid ISO 3166-1 alpha-2 country code
   */
  country: string;
  /**
   * a non empty string
   */
  companyName?: string | undefined;
  /**
   * A valid E.164 phone number
   */
  fax?: string | undefined;
  additional?: Additional | undefined;
};

export type BuySingleDomainRequestBody = {
  /**
   * Whether the domain should be auto-renewed before it expires. This can be configured later through the Vercel Dashboard or the [Update auto-renew for a domain](https://vercel.com/docs/rest-api/reference/endpoints/domains-registrar/update-auto-renew-for-a-domain) endpoint.
   */
  autoRenew: boolean;
  /**
   * The number of years to purchase the domain for.
   */
  years: number;
  expectedPrice: number;
  /**
   * The contact information for the domain. Some TLDs require additional contact information. Use the [Get contact info schema](https://vercel.com/docs/rest-api/reference/endpoints/domains-registrar/get-contact-info-schema) endpoint to retrieve the required fields.
   */
  contactInformation: ContactInformation;
  /**
   * The language code for the domain. For punycode domains, this must be provided. The list of supported language codes for a TLD can be retrieved from the [Get TLD](https://vercel.com/docs/rest-api/reference/endpoints/domains-registrar/get-tld) endpoint.
   */
  languageCode?: string | undefined;
};

export type BuySingleDomainRequest = {
  domain: string;
  teamId?: string | undefined;
  requestBody: BuySingleDomainRequestBody;
};

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

/**
 * There was something wrong with the request
 */
export type BuySingleDomainDomainsRegistrarResponseBody =
  | DomainTooShort
  | OrderTooExpensive
  | InvalidAdditionalContactInfo
  | AdditionalContactInfoRequired
  | ExpectedPriceMismatch
  | DomainNotAvailable
  | LanguageCodeRequired
  | TldNotSupported
  | HttpApiDecodeError;

export const BuySingleDomainMethod = {
  Get: "GET",
  Post: "POST",
  Put: "PUT",
  Delete: "DELETE",
  Patch: "PATCH",
} as const;
export type BuySingleDomainMethod = ClosedEnum<typeof BuySingleDomainMethod>;

export type Links = {
  href: string;
  method: BuySingleDomainMethod;
};

/**
 * Success
 */
export type BuySingleDomainResponseBody = {
  /**
   * A valid order ID
   */
  orderId: string;
  links: { [k: string]: Links };
};

/** @internal */
export type Additional$Outbound = {};

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

export function additionalToJSON(additional: Additional): string {
  return JSON.stringify(Additional$outboundSchema.parse(additional));
}

/** @internal */
export type ContactInformation$Outbound = {
  firstName: string;
  lastName: string;
  email: string;
  phone: string;
  address1: string;
  address2?: string | undefined;
  city: string;
  state: string;
  zip: string;
  country: string;
  companyName?: string | undefined;
  fax?: string | undefined;
  additional?: Additional$Outbound | undefined;
};

/** @internal */
export const ContactInformation$outboundSchema: z.ZodType<
  ContactInformation$Outbound,
  z.ZodTypeDef,
  ContactInformation
> = z.object({
  firstName: z.string(),
  lastName: z.string(),
  email: z.string(),
  phone: z.string(),
  address1: z.string(),
  address2: z.string().optional(),
  city: z.string(),
  state: z.string(),
  zip: z.string(),
  country: z.string(),
  companyName: z.string().optional(),
  fax: z.string().optional(),
  additional: z.lazy(() => Additional$outboundSchema).optional(),
});

export function contactInformationToJSON(
  contactInformation: ContactInformation,
): string {
  return JSON.stringify(
    ContactInformation$outboundSchema.parse(contactInformation),
  );
}

/** @internal */
export type BuySingleDomainRequestBody$Outbound = {
  autoRenew: boolean;
  years: number;
  expectedPrice: number;
  contactInformation: ContactInformation$Outbound;
  languageCode?: string | undefined;
};

/** @internal */
export const BuySingleDomainRequestBody$outboundSchema: z.ZodType<
  BuySingleDomainRequestBody$Outbound,
  z.ZodTypeDef,
  BuySingleDomainRequestBody
> = z.object({
  autoRenew: z.boolean(),
  years: z.number(),
  expectedPrice: z.number(),
  contactInformation: z.lazy(() => ContactInformation$outboundSchema),
  languageCode: z.string().optional(),
});

export function buySingleDomainRequestBodyToJSON(
  buySingleDomainRequestBody: BuySingleDomainRequestBody,
): string {
  return JSON.stringify(
    BuySingleDomainRequestBody$outboundSchema.parse(buySingleDomainRequestBody),
  );
}

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

/** @internal */
export const BuySingleDomainRequest$outboundSchema: z.ZodType<
  BuySingleDomainRequest$Outbound,
  z.ZodTypeDef,
  BuySingleDomainRequest
> = z.object({
  domain: z.string(),
  teamId: z.string().optional(),
  requestBody: z.lazy(() => BuySingleDomainRequestBody$outboundSchema),
}).transform((v) => {
  return remap$(v, {
    requestBody: "RequestBody",
  });
});

export function buySingleDomainRequestToJSON(
  buySingleDomainRequest: BuySingleDomainRequest,
): string {
  return JSON.stringify(
    BuySingleDomainRequest$outboundSchema.parse(buySingleDomainRequest),
  );
}

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

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

/** @internal */
export const BuySingleDomainDomainsRegistrarResponseBody$inboundSchema:
  z.ZodType<
    BuySingleDomainDomainsRegistrarResponseBody,
    z.ZodTypeDef,
    unknown
  > = smartUnion([
    DomainTooShort$inboundSchema,
    OrderTooExpensive$inboundSchema,
    InvalidAdditionalContactInfo$inboundSchema,
    AdditionalContactInfoRequired$inboundSchema,
    ExpectedPriceMismatch$inboundSchema,
    DomainNotAvailable$inboundSchema,
    LanguageCodeRequired$inboundSchema,
    TldNotSupported$inboundSchema,
    HttpApiDecodeError$inboundSchema,
  ]);

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

/** @internal */
export const BuySingleDomainMethod$inboundSchema: z.ZodNativeEnum<
  typeof BuySingleDomainMethod
> = z.nativeEnum(BuySingleDomainMethod);

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

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

/** @internal */
export const BuySingleDomainResponseBody$inboundSchema: z.ZodType<
  BuySingleDomainResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  orderId: types.string(),
  _links: z.record(z.lazy(() => Links$inboundSchema)),
}).transform((v) => {
  return remap$(v, {
    "_links": "links",
  });
});

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