/*
 * 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 { 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-out
 */
export type PatchDomainRequestBody2 = {
  op?: string | undefined;
  /**
   * User or team to move domain to
   */
  destination?: string | undefined;
};

/**
 * update
 */
export type PatchDomainRequestBody1 = {
  op?: string | undefined;
  /**
   * This field is deprecated. Please use PATCH /v1/registrar/domains/{domainName}/auto-renew instead.
   *
   * @deprecated field: This will be removed in a future release, please migrate away from it as soon as possible.
   */
  renew?: boolean | undefined;
  /**
   * This field is deprecated. Please use PATCH /v1/registrar/domains/{domainName}/nameservers instead.
   *
   * @deprecated field: This will be removed in a future release, please migrate away from it as soon as possible.
   */
  customNameservers?: Array<string> | undefined;
  /**
   * Specifies whether this is a DNS zone that intends to use Vercel's nameservers.
   */
  zone?: boolean | undefined;
};

export type PatchDomainRequestBody =
  | PatchDomainRequestBody1
  | PatchDomainRequestBody2;

export type PatchDomainRequest = {
  domain: string;
  /**
   * 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: PatchDomainRequestBody1 | PatchDomainRequestBody2;
};

export type PatchDomainResponseBody3 = {
  renew?: boolean | undefined;
  customNameservers?: Array<string> | undefined;
  zone?: boolean | undefined;
};

export type PatchDomainResponseBody2 = {
  moved: boolean;
  token: string;
};

export type PatchDomainResponseBody1 = {
  moved: boolean;
};

export type PatchDomainResponseBody =
  | PatchDomainResponseBody2
  | PatchDomainResponseBody1
  | PatchDomainResponseBody3;

/** @internal */
export type PatchDomainRequestBody2$Outbound = {
  op?: string | undefined;
  destination?: string | undefined;
};

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

export function patchDomainRequestBody2ToJSON(
  patchDomainRequestBody2: PatchDomainRequestBody2,
): string {
  return JSON.stringify(
    PatchDomainRequestBody2$outboundSchema.parse(patchDomainRequestBody2),
  );
}

/** @internal */
export type PatchDomainRequestBody1$Outbound = {
  op?: string | undefined;
  renew?: boolean | undefined;
  customNameservers?: Array<string> | undefined;
  zone?: boolean | undefined;
};

/** @internal */
export const PatchDomainRequestBody1$outboundSchema: z.ZodType<
  PatchDomainRequestBody1$Outbound,
  z.ZodTypeDef,
  PatchDomainRequestBody1
> = z.object({
  op: z.string().optional(),
  renew: z.boolean().optional(),
  customNameservers: z.array(z.string()).optional(),
  zone: z.boolean().optional(),
});

export function patchDomainRequestBody1ToJSON(
  patchDomainRequestBody1: PatchDomainRequestBody1,
): string {
  return JSON.stringify(
    PatchDomainRequestBody1$outboundSchema.parse(patchDomainRequestBody1),
  );
}

/** @internal */
export type PatchDomainRequestBody$Outbound =
  | PatchDomainRequestBody1$Outbound
  | PatchDomainRequestBody2$Outbound;

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

export function patchDomainRequestBodyToJSON(
  patchDomainRequestBody: PatchDomainRequestBody,
): string {
  return JSON.stringify(
    PatchDomainRequestBody$outboundSchema.parse(patchDomainRequestBody),
  );
}

/** @internal */
export type PatchDomainRequest$Outbound = {
  domain: string;
  teamId?: string | undefined;
  slug?: string | undefined;
  RequestBody:
    | PatchDomainRequestBody1$Outbound
    | PatchDomainRequestBody2$Outbound;
};

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

export function patchDomainRequestToJSON(
  patchDomainRequest: PatchDomainRequest,
): string {
  return JSON.stringify(
    PatchDomainRequest$outboundSchema.parse(patchDomainRequest),
  );
}

/** @internal */
export const PatchDomainResponseBody3$inboundSchema: z.ZodType<
  PatchDomainResponseBody3,
  z.ZodTypeDef,
  unknown
> = z.object({
  renew: types.optional(types.boolean()),
  customNameservers: types.optional(z.array(types.string())),
  zone: types.optional(types.boolean()),
});

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

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

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

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

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

/** @internal */
export const PatchDomainResponseBody$inboundSchema: z.ZodType<
  PatchDomainResponseBody,
  z.ZodTypeDef,
  unknown
> = smartUnion([
  z.lazy(() => PatchDomainResponseBody2$inboundSchema),
  z.lazy(() => PatchDomainResponseBody1$inboundSchema),
  z.lazy(() => PatchDomainResponseBody3$inboundSchema),
]);

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