/*
 * 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";

export type AnalyticsReferers = {
  /**
   * The name of the referer. If unknown, this will be `(direct)`
   */
  referer: string;
  /**
   * The number of clicks from this referer
   */
  clicks?: number | undefined;
  /**
   * The number of leads from this referer
   */
  leads?: number | undefined;
  /**
   * The number of sales from this referer
   */
  sales?: number | undefined;
  /**
   * The total amount of sales from this referer, in cents
   */
  saleAmount?: number | undefined;
};

/** @internal */
export const AnalyticsReferers$inboundSchema: z.ZodType<
  AnalyticsReferers,
  z.ZodTypeDef,
  unknown
> = z.object({
  referer: z.string(),
  clicks: z.number().default(0),
  leads: z.number().default(0),
  sales: z.number().default(0),
  saleAmount: z.number().default(0),
});

/** @internal */
export type AnalyticsReferers$Outbound = {
  referer: string;
  clicks: number;
  leads: number;
  sales: number;
  saleAmount: number;
};

/** @internal */
export const AnalyticsReferers$outboundSchema: z.ZodType<
  AnalyticsReferers$Outbound,
  z.ZodTypeDef,
  AnalyticsReferers
> = z.object({
  referer: z.string(),
  clicks: z.number().default(0),
  leads: z.number().default(0),
  sales: z.number().default(0),
  saleAmount: z.number().default(0),
});

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

export function analyticsReferersToJSON(
  analyticsReferers: AnalyticsReferers,
): string {
  return JSON.stringify(
    AnalyticsReferers$outboundSchema.parse(analyticsReferers),
  );
}

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