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

import * as z from "zod";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

/**
 * The registered domain record.
 */
export type RegisteredDomain = {
  /**
   * The ID of the registered domain record.
   */
  id: string;
  /**
   * The date the domain was created.
   */
  createdAt: string;
  /**
   * The date the domain expires.
   */
  expiresAt: string;
};

export type DomainSchema = {
  /**
   * The unique identifier of the domain.
   */
  id: string;
  /**
   * The domain name.
   */
  slug: string;
  /**
   * Whether the domain is verified.
   */
  verified?: boolean | undefined;
  /**
   * Whether the domain is the primary domain for the workspace.
   */
  primary?: boolean | undefined;
  /**
   * Whether the domain is archived.
   */
  archived?: boolean | undefined;
  /**
   * Provide context to your teammates in the link creation modal by showing them an example of a link to be shortened.
   */
  placeholder: string | null;
  /**
   * The URL to redirect to when a link under this domain has expired.
   */
  expiredUrl: string | null;
  /**
   * The URL to redirect to when a link under this domain doesn't exist.
   */
  notFoundUrl: string | null;
  /**
   * The logo of the domain.
   */
  logo: string | null;
  /**
   * The date the domain was created.
   */
  createdAt: string;
  /**
   * The date the domain was last updated.
   */
  updatedAt: string;
  /**
   * The registered domain record.
   */
  registeredDomain: RegisteredDomain | null;
};

/** @internal */
export const RegisteredDomain$inboundSchema: z.ZodType<
  RegisteredDomain,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: z.string(),
  createdAt: z.string(),
  expiresAt: z.string(),
});

/** @internal */
export type RegisteredDomain$Outbound = {
  id: string;
  createdAt: string;
  expiresAt: string;
};

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

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace RegisteredDomain$ {
  /** @deprecated use `RegisteredDomain$inboundSchema` instead. */
  export const inboundSchema = RegisteredDomain$inboundSchema;
  /** @deprecated use `RegisteredDomain$outboundSchema` instead. */
  export const outboundSchema = RegisteredDomain$outboundSchema;
  /** @deprecated use `RegisteredDomain$Outbound` instead. */
  export type Outbound = RegisteredDomain$Outbound;
}

export function registeredDomainToJSON(
  registeredDomain: RegisteredDomain,
): string {
  return JSON.stringify(
    RegisteredDomain$outboundSchema.parse(registeredDomain),
  );
}

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

/** @internal */
export const DomainSchema$inboundSchema: z.ZodType<
  DomainSchema,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: z.string(),
  slug: z.string(),
  verified: z.boolean().default(false),
  primary: z.boolean().default(false),
  archived: z.boolean().default(false),
  placeholder: z.nullable(z.string()),
  expiredUrl: z.nullable(z.string()),
  notFoundUrl: z.nullable(z.string()),
  logo: z.nullable(z.string()),
  createdAt: z.string(),
  updatedAt: z.string(),
  registeredDomain: z.nullable(z.lazy(() => RegisteredDomain$inboundSchema)),
});

/** @internal */
export type DomainSchema$Outbound = {
  id: string;
  slug: string;
  verified: boolean;
  primary: boolean;
  archived: boolean;
  placeholder: string | null;
  expiredUrl: string | null;
  notFoundUrl: string | null;
  logo: string | null;
  createdAt: string;
  updatedAt: string;
  registeredDomain: RegisteredDomain$Outbound | null;
};

/** @internal */
export const DomainSchema$outboundSchema: z.ZodType<
  DomainSchema$Outbound,
  z.ZodTypeDef,
  DomainSchema
> = z.object({
  id: z.string(),
  slug: z.string(),
  verified: z.boolean().default(false),
  primary: z.boolean().default(false),
  archived: z.boolean().default(false),
  placeholder: z.nullable(z.string()),
  expiredUrl: z.nullable(z.string()),
  notFoundUrl: z.nullable(z.string()),
  logo: z.nullable(z.string()),
  createdAt: z.string(),
  updatedAt: z.string(),
  registeredDomain: z.nullable(z.lazy(() => RegisteredDomain$outboundSchema)),
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace DomainSchema$ {
  /** @deprecated use `DomainSchema$inboundSchema` instead. */
  export const inboundSchema = DomainSchema$inboundSchema;
  /** @deprecated use `DomainSchema$outboundSchema` instead. */
  export const outboundSchema = DomainSchema$outboundSchema;
  /** @deprecated use `DomainSchema$Outbound` instead. */
  export type Outbound = DomainSchema$Outbound;
}

export function domainSchemaToJSON(domainSchema: DomainSchema): string {
  return JSON.stringify(DomainSchema$outboundSchema.parse(domainSchema));
}

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