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

/**
 * The type of the DNS record
 */
export const UpdateRecordType = {
  A: "A",
  Aaaa: "AAAA",
  Alias: "ALIAS",
  Caa: "CAA",
  Cname: "CNAME",
  Https: "HTTPS",
  Mx: "MX",
  Srv: "SRV",
  Txt: "TXT",
  Ns: "NS",
} as const;
/**
 * The type of the DNS record
 */
export type UpdateRecordType = ClosedEnum<typeof UpdateRecordType>;

export type Srv = {
  target: string | null;
  weight: number | null;
  port: number | null;
  priority: number | null;
};

export type Https = {
  priority: number | null;
  target: string | null;
  params?: string | null | undefined;
};

export type UpdateRecordRequestBody = {
  /**
   * The name of the DNS record
   */
  name?: string | null | undefined;
  /**
   * The value of the DNS record
   */
  value?: string | null | undefined;
  /**
   * The type of the DNS record
   */
  type?: UpdateRecordType | null | undefined;
  /**
   * The Time to live (TTL) value of the DNS record
   */
  ttl?: number | null | undefined;
  /**
   * The MX priority value of the DNS record
   */
  mxPriority?: number | null | undefined;
  srv?: Srv | null | undefined;
  https?: Https | null | undefined;
  /**
   * A comment to add context on what this DNS record is for
   */
  comment?: string | undefined;
};

export type UpdateRecordRequest = {
  /**
   * The id of the DNS record
   */
  recordId: 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: UpdateRecordRequestBody;
};

export const UpdateRecordDnsType = {
  Record: "record",
  RecordSys: "record-sys",
} as const;
export type UpdateRecordDnsType = ClosedEnum<typeof UpdateRecordDnsType>;

export const RecordType = {
  A: "A",
  Aaaa: "AAAA",
  Alias: "ALIAS",
  Caa: "CAA",
  Cname: "CNAME",
  Https: "HTTPS",
  Mx: "MX",
  Ns: "NS",
  Srv: "SRV",
  Txt: "TXT",
} as const;
export type RecordType = ClosedEnum<typeof RecordType>;

export type UpdateRecordResponseBody = {
  id: string;
  name: string;
  type: UpdateRecordDnsType;
  value: string;
  creator: string;
  domain: string;
  ttl?: number | undefined;
  comment?: string | undefined;
  recordType: RecordType;
  createdAt?: number | null | undefined;
};

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

/** @internal */
export type Srv$Outbound = {
  target: string | null;
  weight: number | null;
  port: number | null;
  priority: number | null;
};

/** @internal */
export const Srv$outboundSchema: z.ZodType<Srv$Outbound, z.ZodTypeDef, Srv> = z
  .object({
    target: z.nullable(z.string()),
    weight: z.nullable(z.number().int()),
    port: z.nullable(z.number().int()),
    priority: z.nullable(z.number().int()),
  });

export function srvToJSON(srv: Srv): string {
  return JSON.stringify(Srv$outboundSchema.parse(srv));
}

/** @internal */
export type Https$Outbound = {
  priority: number | null;
  target: string | null;
  params?: string | null | undefined;
};

/** @internal */
export const Https$outboundSchema: z.ZodType<
  Https$Outbound,
  z.ZodTypeDef,
  Https
> = z.object({
  priority: z.nullable(z.number().int()),
  target: z.nullable(z.string()),
  params: z.nullable(z.string()).optional(),
});

export function httpsToJSON(https: Https): string {
  return JSON.stringify(Https$outboundSchema.parse(https));
}

/** @internal */
export type UpdateRecordRequestBody$Outbound = {
  name?: string | null | undefined;
  value?: string | null | undefined;
  type?: string | null | undefined;
  ttl?: number | null | undefined;
  mxPriority?: number | null | undefined;
  srv?: Srv$Outbound | null | undefined;
  https?: Https$Outbound | null | undefined;
  comment?: string | undefined;
};

/** @internal */
export const UpdateRecordRequestBody$outboundSchema: z.ZodType<
  UpdateRecordRequestBody$Outbound,
  z.ZodTypeDef,
  UpdateRecordRequestBody
> = z.object({
  name: z.nullable(z.string()).optional(),
  value: z.nullable(z.string()).optional(),
  type: z.nullable(UpdateRecordType$outboundSchema).optional(),
  ttl: z.nullable(z.number().int()).optional(),
  mxPriority: z.nullable(z.number().int()).optional(),
  srv: z.nullable(z.lazy(() => Srv$outboundSchema)).optional(),
  https: z.nullable(z.lazy(() => Https$outboundSchema)).optional(),
  comment: z.string().optional(),
});

export function updateRecordRequestBodyToJSON(
  updateRecordRequestBody: UpdateRecordRequestBody,
): string {
  return JSON.stringify(
    UpdateRecordRequestBody$outboundSchema.parse(updateRecordRequestBody),
  );
}

/** @internal */
export type UpdateRecordRequest$Outbound = {
  recordId: string;
  teamId?: string | undefined;
  slug?: string | undefined;
  RequestBody: UpdateRecordRequestBody$Outbound;
};

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

export function updateRecordRequestToJSON(
  updateRecordRequest: UpdateRecordRequest,
): string {
  return JSON.stringify(
    UpdateRecordRequest$outboundSchema.parse(updateRecordRequest),
  );
}

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

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

/** @internal */
export const UpdateRecordResponseBody$inboundSchema: z.ZodType<
  UpdateRecordResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: types.string(),
  name: types.string(),
  type: UpdateRecordDnsType$inboundSchema,
  value: types.string(),
  creator: types.string(),
  domain: types.string(),
  ttl: types.optional(types.number()),
  comment: types.optional(types.string()),
  recordType: RecordType$inboundSchema,
  createdAt: z.nullable(types.number()).optional(),
});

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