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

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

export type UpdateCustomerRequestBody = {
  /**
   * 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 | undefined;
};

export type UpdateCustomerRequest = {
  /**
   * The unique identifier of the customer in Dub.
   */
  id: string;
  /**
   * Whether to include expanded fields on the customer (`link`, `partner`, `discount`).
   */
  includeExpandedFields?: boolean | undefined;
  requestBody?: UpdateCustomerRequestBody | undefined;
};

export type UpdateCustomerLink = {
  /**
   * 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 UpdateCustomerPartner = {
  id: string;
  name: string;
  email: string;
  image?: string | null | undefined;
};

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

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

export type UpdateCustomerDiscount = {
  id: string;
  couponId: string | null;
  couponTestId: string | null;
  amount: number;
  type: UpdateCustomerType;
  duration: number | null;
  interval: UpdateCustomerInterval | null;
};

/**
 * The customer was updated.
 */
export type UpdateCustomerResponseBody = {
  /**
   * 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?: UpdateCustomerLink | null | undefined;
  partner?: UpdateCustomerPartner | null | undefined;
  discount?: UpdateCustomerDiscount | null | undefined;
};

/** @internal */
export const UpdateCustomerRequestBody$inboundSchema: z.ZodType<
  UpdateCustomerRequestBody,
  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().optional(),
});

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

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

export function updateCustomerRequestBodyToJSON(
  updateCustomerRequestBody: UpdateCustomerRequestBody,
): string {
  return JSON.stringify(
    UpdateCustomerRequestBody$outboundSchema.parse(updateCustomerRequestBody),
  );
}

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

/** @internal */
export const UpdateCustomerRequest$inboundSchema: z.ZodType<
  UpdateCustomerRequest,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: z.string(),
  includeExpandedFields: z.boolean().optional(),
  RequestBody: z.lazy(() => UpdateCustomerRequestBody$inboundSchema).optional(),
}).transform((v) => {
  return remap$(v, {
    "RequestBody": "requestBody",
  });
});

/** @internal */
export type UpdateCustomerRequest$Outbound = {
  id: string;
  includeExpandedFields?: boolean | undefined;
  RequestBody?: UpdateCustomerRequestBody$Outbound | undefined;
};

/** @internal */
export const UpdateCustomerRequest$outboundSchema: z.ZodType<
  UpdateCustomerRequest$Outbound,
  z.ZodTypeDef,
  UpdateCustomerRequest
> = z.object({
  id: z.string(),
  includeExpandedFields: z.boolean().optional(),
  requestBody: z.lazy(() => UpdateCustomerRequestBody$outboundSchema)
    .optional(),
}).transform((v) => {
  return remap$(v, {
    requestBody: "RequestBody",
  });
});

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

export function updateCustomerRequestToJSON(
  updateCustomerRequest: UpdateCustomerRequest,
): string {
  return JSON.stringify(
    UpdateCustomerRequest$outboundSchema.parse(updateCustomerRequest),
  );
}

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

/** @internal */
export const UpdateCustomerLink$inboundSchema: z.ZodType<
  UpdateCustomerLink,
  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 UpdateCustomerLink$Outbound = {
  id: string;
  domain: string;
  key: string;
  shortLink: string;
  programId: string | null;
};

/** @internal */
export const UpdateCustomerLink$outboundSchema: z.ZodType<
  UpdateCustomerLink$Outbound,
  z.ZodTypeDef,
  UpdateCustomerLink
> = 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 UpdateCustomerLink$ {
  /** @deprecated use `UpdateCustomerLink$inboundSchema` instead. */
  export const inboundSchema = UpdateCustomerLink$inboundSchema;
  /** @deprecated use `UpdateCustomerLink$outboundSchema` instead. */
  export const outboundSchema = UpdateCustomerLink$outboundSchema;
  /** @deprecated use `UpdateCustomerLink$Outbound` instead. */
  export type Outbound = UpdateCustomerLink$Outbound;
}

export function updateCustomerLinkToJSON(
  updateCustomerLink: UpdateCustomerLink,
): string {
  return JSON.stringify(
    UpdateCustomerLink$outboundSchema.parse(updateCustomerLink),
  );
}

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

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

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

/** @internal */
export const UpdateCustomerPartner$outboundSchema: z.ZodType<
  UpdateCustomerPartner$Outbound,
  z.ZodTypeDef,
  UpdateCustomerPartner
> = 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 UpdateCustomerPartner$ {
  /** @deprecated use `UpdateCustomerPartner$inboundSchema` instead. */
  export const inboundSchema = UpdateCustomerPartner$inboundSchema;
  /** @deprecated use `UpdateCustomerPartner$outboundSchema` instead. */
  export const outboundSchema = UpdateCustomerPartner$outboundSchema;
  /** @deprecated use `UpdateCustomerPartner$Outbound` instead. */
  export type Outbound = UpdateCustomerPartner$Outbound;
}

export function updateCustomerPartnerToJSON(
  updateCustomerPartner: UpdateCustomerPartner,
): string {
  return JSON.stringify(
    UpdateCustomerPartner$outboundSchema.parse(updateCustomerPartner),
  );
}

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

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

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

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

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

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

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

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

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

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

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

export function updateCustomerDiscountToJSON(
  updateCustomerDiscount: UpdateCustomerDiscount,
): string {
  return JSON.stringify(
    UpdateCustomerDiscount$outboundSchema.parse(updateCustomerDiscount),
  );
}

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

/** @internal */
export const UpdateCustomerResponseBody$inboundSchema: z.ZodType<
  UpdateCustomerResponseBody,
  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(() => UpdateCustomerLink$inboundSchema)).optional(),
  partner: z.nullable(z.lazy(() => UpdateCustomerPartner$inboundSchema))
    .optional(),
  discount: z.nullable(z.lazy(() => UpdateCustomerDiscount$inboundSchema))
    .optional(),
});

/** @internal */
export type UpdateCustomerResponseBody$Outbound = {
  id: string;
  externalId: string;
  name: string;
  email?: string | null | undefined;
  avatar?: string | null | undefined;
  country?: string | null | undefined;
  createdAt: string;
  link?: UpdateCustomerLink$Outbound | null | undefined;
  partner?: UpdateCustomerPartner$Outbound | null | undefined;
  discount?: UpdateCustomerDiscount$Outbound | null | undefined;
};

/** @internal */
export const UpdateCustomerResponseBody$outboundSchema: z.ZodType<
  UpdateCustomerResponseBody$Outbound,
  z.ZodTypeDef,
  UpdateCustomerResponseBody
> = 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(() => UpdateCustomerLink$outboundSchema)).optional(),
  partner: z.nullable(z.lazy(() => UpdateCustomerPartner$outboundSchema))
    .optional(),
  discount: z.nullable(z.lazy(() => UpdateCustomerDiscount$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 UpdateCustomerResponseBody$ {
  /** @deprecated use `UpdateCustomerResponseBody$inboundSchema` instead. */
  export const inboundSchema = UpdateCustomerResponseBody$inboundSchema;
  /** @deprecated use `UpdateCustomerResponseBody$outboundSchema` instead. */
  export const outboundSchema = UpdateCustomerResponseBody$outboundSchema;
  /** @deprecated use `UpdateCustomerResponseBody$Outbound` instead. */
  export type Outbound = UpdateCustomerResponseBody$Outbound;
}

export function updateCustomerResponseBodyToJSON(
  updateCustomerResponseBody: UpdateCustomerResponseBody,
): string {
  return JSON.stringify(
    UpdateCustomerResponseBody$outboundSchema.parse(updateCustomerResponseBody),
  );
}

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