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

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

export type CreateCustomerRequestBody = {
  /**
   * Email of the customer in the client's app.
   */
  email?: string | null | undefined;
  /**
   * Name of the customer in the client's app. If not provided, a random name will be generated.
   */
  name?: string | null | undefined;
  /**
   * Avatar URL of the customer in the client's app.
   */
  avatar?: string | null | undefined;
  /**
   * Unique identifier for the customer in the client's app.
   */
  externalId: string;
};

export type CreateCustomerLink = {
  /**
   * The unique ID of the short link.
   */
  id: string;
  /**
   * The domain of the short link. If not provided, the primary domain for the workspace will be used (or `dub.sh` if the workspace has no domains).
   */
  domain: string;
  /**
   * The short link slug. If not provided, a random 7-character slug will be generated.
   */
  key: string;
  /**
   * The full URL of the short link, including the https protocol (e.g. `https://dub.sh/try`).
   */
  shortLink: string;
  /**
   * The ID of the program the short link is associated with.
   */
  programId: string | null;
};

export type CreateCustomerPartner = {
  id: string;
  name: string;
  email: string;
  image?: string | null | undefined;
};

export const CreateCustomerType = {
  Percentage: "percentage",
  Flat: "flat",
} as const;
export type CreateCustomerType = ClosedEnum<typeof CreateCustomerType>;

export const CreateCustomerInterval = {
  Month: "month",
  Year: "year",
} as const;
export type CreateCustomerInterval = ClosedEnum<typeof CreateCustomerInterval>;

export type CreateCustomerDiscount = {
  id: string;
  couponId: string | null;
  couponTestId: string | null;
  amount: number;
  type: CreateCustomerType;
  duration: number | null;
  interval: CreateCustomerInterval | null;
};

/**
 * The customer was created.
 */
export type CreateCustomerResponseBody = {
  /**
   * The unique identifier of the customer in Dub.
   */
  id: string;
  /**
   * Unique identifier for the customer in the client's app.
   */
  externalId: string;
  /**
   * Name of the customer.
   */
  name: string;
  /**
   * Email of the customer.
   */
  email?: string | null | undefined;
  /**
   * Avatar URL of the customer.
   */
  avatar?: string | null | undefined;
  /**
   * Country of the customer.
   */
  country?: string | null | undefined;
  /**
   * The date the customer was created.
   */
  createdAt: string;
  link?: CreateCustomerLink | null | undefined;
  partner?: CreateCustomerPartner | null | undefined;
  discount?: CreateCustomerDiscount | null | undefined;
};

/** @internal */
export const CreateCustomerRequestBody$inboundSchema: z.ZodType<
  CreateCustomerRequestBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  email: z.nullable(z.string()).optional(),
  name: z.nullable(z.string()).optional(),
  avatar: z.nullable(z.string()).optional(),
  externalId: z.string(),
});

/** @internal */
export type CreateCustomerRequestBody$Outbound = {
  email?: string | null | undefined;
  name?: string | null | undefined;
  avatar?: string | null | undefined;
  externalId: string;
};

/** @internal */
export const CreateCustomerRequestBody$outboundSchema: z.ZodType<
  CreateCustomerRequestBody$Outbound,
  z.ZodTypeDef,
  CreateCustomerRequestBody
> = z.object({
  email: z.nullable(z.string()).optional(),
  name: z.nullable(z.string()).optional(),
  avatar: z.nullable(z.string()).optional(),
  externalId: 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 CreateCustomerRequestBody$ {
  /** @deprecated use `CreateCustomerRequestBody$inboundSchema` instead. */
  export const inboundSchema = CreateCustomerRequestBody$inboundSchema;
  /** @deprecated use `CreateCustomerRequestBody$outboundSchema` instead. */
  export const outboundSchema = CreateCustomerRequestBody$outboundSchema;
  /** @deprecated use `CreateCustomerRequestBody$Outbound` instead. */
  export type Outbound = CreateCustomerRequestBody$Outbound;
}

export function createCustomerRequestBodyToJSON(
  createCustomerRequestBody: CreateCustomerRequestBody,
): string {
  return JSON.stringify(
    CreateCustomerRequestBody$outboundSchema.parse(createCustomerRequestBody),
  );
}

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

/** @internal */
export const CreateCustomerLink$inboundSchema: z.ZodType<
  CreateCustomerLink,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: z.string(),
  domain: z.string(),
  key: z.string(),
  shortLink: z.string(),
  programId: z.nullable(z.string()),
});

/** @internal */
export type CreateCustomerLink$Outbound = {
  id: string;
  domain: string;
  key: string;
  shortLink: string;
  programId: string | null;
};

/** @internal */
export const CreateCustomerLink$outboundSchema: z.ZodType<
  CreateCustomerLink$Outbound,
  z.ZodTypeDef,
  CreateCustomerLink
> = z.object({
  id: z.string(),
  domain: z.string(),
  key: z.string(),
  shortLink: z.string(),
  programId: z.nullable(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 CreateCustomerLink$ {
  /** @deprecated use `CreateCustomerLink$inboundSchema` instead. */
  export const inboundSchema = CreateCustomerLink$inboundSchema;
  /** @deprecated use `CreateCustomerLink$outboundSchema` instead. */
  export const outboundSchema = CreateCustomerLink$outboundSchema;
  /** @deprecated use `CreateCustomerLink$Outbound` instead. */
  export type Outbound = CreateCustomerLink$Outbound;
}

export function createCustomerLinkToJSON(
  createCustomerLink: CreateCustomerLink,
): string {
  return JSON.stringify(
    CreateCustomerLink$outboundSchema.parse(createCustomerLink),
  );
}

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

/** @internal */
export const CreateCustomerPartner$inboundSchema: z.ZodType<
  CreateCustomerPartner,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: z.string(),
  name: z.string(),
  email: z.string(),
  image: z.nullable(z.string()).optional(),
});

/** @internal */
export type CreateCustomerPartner$Outbound = {
  id: string;
  name: string;
  email: string;
  image?: string | null | undefined;
};

/** @internal */
export const CreateCustomerPartner$outboundSchema: z.ZodType<
  CreateCustomerPartner$Outbound,
  z.ZodTypeDef,
  CreateCustomerPartner
> = z.object({
  id: z.string(),
  name: z.string(),
  email: z.string(),
  image: z.nullable(z.string()).optional(),
});

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

export function createCustomerPartnerToJSON(
  createCustomerPartner: CreateCustomerPartner,
): string {
  return JSON.stringify(
    CreateCustomerPartner$outboundSchema.parse(createCustomerPartner),
  );
}

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

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

/** @internal */
export const CreateCustomerType$outboundSchema: z.ZodNativeEnum<
  typeof CreateCustomerType
> = CreateCustomerType$inboundSchema;

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

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

/** @internal */
export const CreateCustomerInterval$outboundSchema: z.ZodNativeEnum<
  typeof CreateCustomerInterval
> = CreateCustomerInterval$inboundSchema;

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

/** @internal */
export const CreateCustomerDiscount$inboundSchema: z.ZodType<
  CreateCustomerDiscount,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: z.string(),
  couponId: z.nullable(z.string()),
  couponTestId: z.nullable(z.string()),
  amount: z.number(),
  type: CreateCustomerType$inboundSchema,
  duration: z.nullable(z.number()),
  interval: z.nullable(CreateCustomerInterval$inboundSchema),
});

/** @internal */
export type CreateCustomerDiscount$Outbound = {
  id: string;
  couponId: string | null;
  couponTestId: string | null;
  amount: number;
  type: string;
  duration: number | null;
  interval: string | null;
};

/** @internal */
export const CreateCustomerDiscount$outboundSchema: z.ZodType<
  CreateCustomerDiscount$Outbound,
  z.ZodTypeDef,
  CreateCustomerDiscount
> = z.object({
  id: z.string(),
  couponId: z.nullable(z.string()),
  couponTestId: z.nullable(z.string()),
  amount: z.number(),
  type: CreateCustomerType$outboundSchema,
  duration: z.nullable(z.number()),
  interval: z.nullable(CreateCustomerInterval$outboundSchema),
});

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

export function createCustomerDiscountToJSON(
  createCustomerDiscount: CreateCustomerDiscount,
): string {
  return JSON.stringify(
    CreateCustomerDiscount$outboundSchema.parse(createCustomerDiscount),
  );
}

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

/** @internal */
export const CreateCustomerResponseBody$inboundSchema: z.ZodType<
  CreateCustomerResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: z.string(),
  externalId: z.string(),
  name: z.string(),
  email: z.nullable(z.string()).optional(),
  avatar: z.nullable(z.string()).optional(),
  country: z.nullable(z.string()).optional(),
  createdAt: z.string(),
  link: z.nullable(z.lazy(() => CreateCustomerLink$inboundSchema)).optional(),
  partner: z.nullable(z.lazy(() => CreateCustomerPartner$inboundSchema))
    .optional(),
  discount: z.nullable(z.lazy(() => CreateCustomerDiscount$inboundSchema))
    .optional(),
});

/** @internal */
export type CreateCustomerResponseBody$Outbound = {
  id: string;
  externalId: string;
  name: string;
  email?: string | null | undefined;
  avatar?: string | null | undefined;
  country?: string | null | undefined;
  createdAt: string;
  link?: CreateCustomerLink$Outbound | null | undefined;
  partner?: CreateCustomerPartner$Outbound | null | undefined;
  discount?: CreateCustomerDiscount$Outbound | null | undefined;
};

/** @internal */
export const CreateCustomerResponseBody$outboundSchema: z.ZodType<
  CreateCustomerResponseBody$Outbound,
  z.ZodTypeDef,
  CreateCustomerResponseBody
> = z.object({
  id: z.string(),
  externalId: z.string(),
  name: z.string(),
  email: z.nullable(z.string()).optional(),
  avatar: z.nullable(z.string()).optional(),
  country: z.nullable(z.string()).optional(),
  createdAt: z.string(),
  link: z.nullable(z.lazy(() => CreateCustomerLink$outboundSchema)).optional(),
  partner: z.nullable(z.lazy(() => CreateCustomerPartner$outboundSchema))
    .optional(),
  discount: z.nullable(z.lazy(() => CreateCustomerDiscount$outboundSchema))
    .optional(),
});

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

export function createCustomerResponseBodyToJSON(
  createCustomerResponseBody: CreateCustomerResponseBody,
): string {
  return JSON.stringify(
    CreateCustomerResponseBody$outboundSchema.parse(createCustomerResponseBody),
  );
}

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