/*
 * 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 { SDKValidationError } from "./sdkvalidationerror.js";

/**
 * move-in
 */
export type CreateOrTransferDomainRequestBody2 = {
  /**
   * The domain name you want to add.
   */
  name: string;
  /**
   * The domain operation to perform. It can be either `add` or `move-in`.
   */
  method: string;
  /**
   * The move-in token from Move Requested email.
   */
  token?: string | undefined;
};

/**
 * add
 */
export type CreateOrTransferDomainRequestBody1 = {
  /**
   * The domain name you want to add.
   */
  name: string;
  /**
   * Whether the domain has the Vercel Edge Network enabled or not.
   */
  cdnEnabled?: boolean | undefined;
  /**
   * Whether to create a DNS zone on Vercel. Set `true` if using Vercel nameservers.
   */
  zone?: boolean | undefined;
  /**
   * The domain operation to perform. It can be either `add` or `move-in`.
   */
  method?: string | undefined;
};

export type CreateOrTransferDomainRequestBody =
  | CreateOrTransferDomainRequestBody2
  | CreateOrTransferDomainRequestBody1;

export type CreateOrTransferDomainRequest = {
  /**
   * The Team identifier to perform the request on behalf of.
   */
  teamId?: string | undefined;
  /**
   * The Team slug to perform the request on behalf of.
   */
  slug?: string | undefined;
  requestBody?:
    | CreateOrTransferDomainRequestBody2
    | CreateOrTransferDomainRequestBody1
    | undefined;
};

/**
 * An object containing information of the domain creator, including the user's id, username, and email.
 */
export type CreateOrTransferDomainCreator = {
  username: string;
  email: string;
  customerId?: string | null | undefined;
  isDomainReseller?: boolean | undefined;
  id: string;
};

/**
 * The type of service the domain is handled by. `external` if the DNS is externally handled, `zeit.world` if handled with Vercel, or `na` if the service is not available.
 */
export const CreateOrTransferDomainServiceType = {
  External: "external",
  Na: "na",
  ZeitWorld: "zeit.world",
} as const;
/**
 * The type of service the domain is handled by. `external` if the DNS is externally handled, `zeit.world` if handled with Vercel, or `na` if the service is not available.
 */
export type CreateOrTransferDomainServiceType = ClosedEnum<
  typeof CreateOrTransferDomainServiceType
>;

export type CreateOrTransferDomainDomain = {
  /**
   * Timestamp in milliseconds at which the domain is set to expire. null if not bought with Vercel.
   */
  expiresAt: number | null;
  /**
   * If the domain has the ownership verified.
   */
  verified: boolean;
  /**
   * A list of the current nameservers of the domain.
   */
  nameservers: Array<string>;
  /**
   * A list of the intended nameservers for the domain to point to Vercel DNS.
   */
  intendedNameservers: Array<string>;
  /**
   * A list of custom nameservers for the domain to point to. Only applies to domains purchased with Vercel.
   */
  customNameservers?: Array<string> | undefined;
  /**
   * An object containing information of the domain creator, including the user's id, username, and email.
   */
  creator: CreateOrTransferDomainCreator;
  /**
   * The domain name.
   */
  name: string;
  teamId: string | null;
  /**
   * If it was purchased through Vercel, the timestamp in milliseconds when it was purchased.
   */
  boughtAt: number | null;
  /**
   * Timestamp in milliseconds when the domain was created in the registry.
   */
  createdAt: number;
  /**
   * The unique identifier of the domain.
   */
  id: string;
  /**
   * Indicates whether the domain is set to automatically renew.
   */
  renew?: boolean | undefined;
  /**
   * The type of service the domain is handled by. `external` if the DNS is externally handled, `zeit.world` if handled with Vercel, or `na` if the service is not available.
   */
  serviceType: CreateOrTransferDomainServiceType;
  /**
   * Timestamp in milliseconds at which the domain was successfully transferred into Vercel. `null` if the transfer is still processing or was never transferred in.
   */
  transferredAt?: number | null | undefined;
  /**
   * If transferred into Vercel, timestamp in milliseconds when the domain transfer was initiated.
   */
  transferStartedAt?: number | undefined;
  userId: string;
};

export type CreateOrTransferDomainResponseBody = {
  domain: CreateOrTransferDomainDomain;
};

/** @internal */
export type CreateOrTransferDomainRequestBody2$Outbound = {
  name: string;
  method: string;
  token?: string | undefined;
};

/** @internal */
export const CreateOrTransferDomainRequestBody2$outboundSchema: z.ZodType<
  CreateOrTransferDomainRequestBody2$Outbound,
  z.ZodTypeDef,
  CreateOrTransferDomainRequestBody2
> = z.object({
  name: z.string(),
  method: z.string(),
  token: z.string().optional(),
});

export function createOrTransferDomainRequestBody2ToJSON(
  createOrTransferDomainRequestBody2: CreateOrTransferDomainRequestBody2,
): string {
  return JSON.stringify(
    CreateOrTransferDomainRequestBody2$outboundSchema.parse(
      createOrTransferDomainRequestBody2,
    ),
  );
}

/** @internal */
export type CreateOrTransferDomainRequestBody1$Outbound = {
  name: string;
  cdnEnabled?: boolean | undefined;
  zone?: boolean | undefined;
  method?: string | undefined;
};

/** @internal */
export const CreateOrTransferDomainRequestBody1$outboundSchema: z.ZodType<
  CreateOrTransferDomainRequestBody1$Outbound,
  z.ZodTypeDef,
  CreateOrTransferDomainRequestBody1
> = z.object({
  name: z.string(),
  cdnEnabled: z.boolean().optional(),
  zone: z.boolean().optional(),
  method: z.string().optional(),
});

export function createOrTransferDomainRequestBody1ToJSON(
  createOrTransferDomainRequestBody1: CreateOrTransferDomainRequestBody1,
): string {
  return JSON.stringify(
    CreateOrTransferDomainRequestBody1$outboundSchema.parse(
      createOrTransferDomainRequestBody1,
    ),
  );
}

/** @internal */
export type CreateOrTransferDomainRequestBody$Outbound =
  | CreateOrTransferDomainRequestBody2$Outbound
  | CreateOrTransferDomainRequestBody1$Outbound;

/** @internal */
export const CreateOrTransferDomainRequestBody$outboundSchema: z.ZodType<
  CreateOrTransferDomainRequestBody$Outbound,
  z.ZodTypeDef,
  CreateOrTransferDomainRequestBody
> = smartUnion([
  z.lazy(() => CreateOrTransferDomainRequestBody2$outboundSchema),
  z.lazy(() => CreateOrTransferDomainRequestBody1$outboundSchema),
]);

export function createOrTransferDomainRequestBodyToJSON(
  createOrTransferDomainRequestBody: CreateOrTransferDomainRequestBody,
): string {
  return JSON.stringify(
    CreateOrTransferDomainRequestBody$outboundSchema.parse(
      createOrTransferDomainRequestBody,
    ),
  );
}

/** @internal */
export type CreateOrTransferDomainRequest$Outbound = {
  teamId?: string | undefined;
  slug?: string | undefined;
  RequestBody?:
    | CreateOrTransferDomainRequestBody2$Outbound
    | CreateOrTransferDomainRequestBody1$Outbound
    | undefined;
};

/** @internal */
export const CreateOrTransferDomainRequest$outboundSchema: z.ZodType<
  CreateOrTransferDomainRequest$Outbound,
  z.ZodTypeDef,
  CreateOrTransferDomainRequest
> = z.object({
  teamId: z.string().optional(),
  slug: z.string().optional(),
  requestBody: smartUnion([
    z.lazy(() => CreateOrTransferDomainRequestBody2$outboundSchema),
    z.lazy(() => CreateOrTransferDomainRequestBody1$outboundSchema),
  ]).optional(),
}).transform((v) => {
  return remap$(v, {
    requestBody: "RequestBody",
  });
});

export function createOrTransferDomainRequestToJSON(
  createOrTransferDomainRequest: CreateOrTransferDomainRequest,
): string {
  return JSON.stringify(
    CreateOrTransferDomainRequest$outboundSchema.parse(
      createOrTransferDomainRequest,
    ),
  );
}

/** @internal */
export const CreateOrTransferDomainCreator$inboundSchema: z.ZodType<
  CreateOrTransferDomainCreator,
  z.ZodTypeDef,
  unknown
> = z.object({
  username: types.string(),
  email: types.string(),
  customerId: z.nullable(types.string()).optional(),
  isDomainReseller: types.optional(types.boolean()),
  id: types.string(),
});

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

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

/** @internal */
export const CreateOrTransferDomainDomain$inboundSchema: z.ZodType<
  CreateOrTransferDomainDomain,
  z.ZodTypeDef,
  unknown
> = z.object({
  expiresAt: types.nullable(types.number()),
  verified: types.boolean(),
  nameservers: z.array(types.string()),
  intendedNameservers: z.array(types.string()),
  customNameservers: types.optional(z.array(types.string())),
  creator: z.lazy(() => CreateOrTransferDomainCreator$inboundSchema),
  name: types.string(),
  teamId: types.nullable(types.string()),
  boughtAt: types.nullable(types.number()),
  createdAt: types.number(),
  id: types.string(),
  renew: types.optional(types.boolean()),
  serviceType: CreateOrTransferDomainServiceType$inboundSchema,
  transferredAt: z.nullable(types.number()).optional(),
  transferStartedAt: types.optional(types.number()),
  userId: types.string(),
});

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

/** @internal */
export const CreateOrTransferDomainResponseBody$inboundSchema: z.ZodType<
  CreateOrTransferDomainResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  domain: z.lazy(() => CreateOrTransferDomainDomain$inboundSchema),
});

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