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

import * as z from "zod/v3";
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 { SDKValidationError } from "./sdkvalidationerror.js";

export type ClaimDomainOwnershipRequest = {
  /**
   * The domain name to claim ownership of
   */
  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;
};

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

/**
 * Whether the domain is enrolled in Encrypted Client Hello. `auto` leaves the decision to Vercel, `enabled` always enrolls, and `disabled` never enrolls and opts out of automatic enrollment.
 */
export const ClaimDomainOwnershipEchMode = {
  Auto: "auto",
  Disabled: "disabled",
  Enabled: "enabled",
} as const;
/**
 * Whether the domain is enrolled in Encrypted Client Hello. `auto` leaves the decision to Vercel, `enabled` always enrolls, and `disabled` never enrolls and opts out of automatic enrollment.
 */
export type ClaimDomainOwnershipEchMode = ClosedEnum<
  typeof ClaimDomainOwnershipEchMode
>;

/**
 * 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 ServiceType = {
  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 ServiceType = ClosedEnum<typeof ServiceType>;

export type ClaimDomainOwnershipDomain = {
  /**
   * 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: ClaimDomainOwnershipCreator;
  /**
   * Whether the domain is enrolled in Encrypted Client Hello. `auto` leaves the decision to Vercel, `enabled` always enrolls, and `disabled` never enrolls and opts out of automatic enrollment.
   */
  echMode: ClaimDomainOwnershipEchMode;
  /**
   * 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: ServiceType;
  /**
   * 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;
};

/**
 * Domain ownership successfully claimed.
 */
export type ClaimDomainOwnershipResponseBody = {
  domain: ClaimDomainOwnershipDomain;
};

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

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

export function claimDomainOwnershipRequestToJSON(
  claimDomainOwnershipRequest: ClaimDomainOwnershipRequest,
): string {
  return JSON.stringify(
    ClaimDomainOwnershipRequest$outboundSchema.parse(
      claimDomainOwnershipRequest,
    ),
  );
}

/** @internal */
export const ClaimDomainOwnershipCreator$inboundSchema: z.ZodType<
  ClaimDomainOwnershipCreator,
  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 claimDomainOwnershipCreatorFromJSON(
  jsonString: string,
): SafeParseResult<ClaimDomainOwnershipCreator, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ClaimDomainOwnershipCreator$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ClaimDomainOwnershipCreator' from JSON`,
  );
}

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

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

/** @internal */
export const ClaimDomainOwnershipDomain$inboundSchema: z.ZodType<
  ClaimDomainOwnershipDomain,
  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(() => ClaimDomainOwnershipCreator$inboundSchema),
  echMode: ClaimDomainOwnershipEchMode$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: ServiceType$inboundSchema,
  transferredAt: z.nullable(types.number()).optional(),
  transferStartedAt: types.optional(types.number()),
  userId: types.string(),
});

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

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

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