/*
 * 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 AnalyticsRefererUrls = {
  /**
   * The full URL of the referer. If unknown, this will be `(direct)`
   */
  refererUrl: string;
  /**
   * The number of clicks from this referer to this URL
   */
  clicks?: number | undefined;
  /**
   * The number of leads from this referer to this URL
   */
  leads?: number | undefined;
  /**
   * The number of sales from this referer to this URL
   */
  sales?: number | undefined;
  /**
   * The total amount of sales from this referer to this URL, in cents
   */
  saleAmount?: number | undefined;
};

/** @internal */
export const AnalyticsRefererUrls$inboundSchema: z.ZodType<
  AnalyticsRefererUrls,
  z.ZodTypeDef,
  unknown
> = z.object({
  refererUrl: 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 AnalyticsRefererUrls$Outbound = {
  refererUrl: string;
  clicks: number;
  leads: number;
  sales: number;
  saleAmount: number;
};

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

export function analyticsRefererUrlsToJSON(
  analyticsRefererUrls: AnalyticsRefererUrls,
): string {
  return JSON.stringify(
    AnalyticsRefererUrls$outboundSchema.parse(analyticsRefererUrls),
  );
}

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