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

import * as z from "zod/v3";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  EventFilter,
  EventFilter$inboundSchema,
  EventFilter$Outbound,
  EventFilter$outboundSchema,
} from "./eventfilter.js";
import {
  MetricDataSourceRefRep,
  MetricDataSourceRefRep$inboundSchema,
  MetricDataSourceRefRep$Outbound,
  MetricDataSourceRefRep$outboundSchema,
} from "./metricdatasourcerefrep.js";

export type DenominatorPost = {
  /**
   * The warehouse event column for the denominator. Required.
   */
  eventName?: string | undefined;
  /**
   * Whether the denominator aggregates a numeric value
   */
  isNumeric?: boolean | undefined;
  dataSource?: MetricDataSourceRefRep | undefined;
  /**
   * How individual unit values are aggregated. One of: average, sum, count_distinct
   */
  unitAggregationType?: string | undefined;
  /**
   * The warehouse column to use for counting distinct values. Required when the unitAggregationType is count_distinct.
   */
  unitAggregationField?: string | undefined;
  /**
   * For a numeric denominator, the column holding the numeric value. Overrides the value column mapped on the denominator data source.
   */
  valueColumn?: string | undefined;
  filters?: EventFilter | undefined;
  /**
   * Start of the measurement window in milliseconds
   */
  windowStartOffset?: number | undefined;
  /**
   * End of the measurement window in milliseconds
   */
  windowEndOffset?: number | undefined;
  /**
   * Lower winsorization percentile in the open interval (0, 100)
   */
  winsorLowerPercentile?: number | undefined;
  /**
   * Upper winsorization percentile in the open interval (0, 100)
   */
  winsorUpperPercentile?: number | undefined;
  /**
   * When true, includes imputed zeros in the percentile bound calculation
   */
  winsorIncludeImputed?: boolean | undefined;
};

/** @internal */
export const DenominatorPost$inboundSchema: z.ZodType<
  DenominatorPost,
  z.ZodTypeDef,
  unknown
> = z.object({
  eventName: z.string().optional(),
  isNumeric: z.boolean().optional(),
  dataSource: MetricDataSourceRefRep$inboundSchema.optional(),
  unitAggregationType: z.string().optional(),
  unitAggregationField: z.string().optional(),
  valueColumn: z.string().optional(),
  filters: EventFilter$inboundSchema.optional(),
  windowStartOffset: z.number().int().optional(),
  windowEndOffset: z.number().int().optional(),
  winsorLowerPercentile: z.number().optional(),
  winsorUpperPercentile: z.number().optional(),
  winsorIncludeImputed: z.boolean().optional(),
});
/** @internal */
export type DenominatorPost$Outbound = {
  eventName?: string | undefined;
  isNumeric?: boolean | undefined;
  dataSource?: MetricDataSourceRefRep$Outbound | undefined;
  unitAggregationType?: string | undefined;
  unitAggregationField?: string | undefined;
  valueColumn?: string | undefined;
  filters?: EventFilter$Outbound | undefined;
  windowStartOffset?: number | undefined;
  windowEndOffset?: number | undefined;
  winsorLowerPercentile?: number | undefined;
  winsorUpperPercentile?: number | undefined;
  winsorIncludeImputed?: boolean | undefined;
};

/** @internal */
export const DenominatorPost$outboundSchema: z.ZodType<
  DenominatorPost$Outbound,
  z.ZodTypeDef,
  DenominatorPost
> = z.object({
  eventName: z.string().optional(),
  isNumeric: z.boolean().optional(),
  dataSource: MetricDataSourceRefRep$outboundSchema.optional(),
  unitAggregationType: z.string().optional(),
  unitAggregationField: z.string().optional(),
  valueColumn: z.string().optional(),
  filters: EventFilter$outboundSchema.optional(),
  windowStartOffset: z.number().int().optional(),
  windowEndOffset: z.number().int().optional(),
  winsorLowerPercentile: z.number().optional(),
  winsorUpperPercentile: z.number().optional(),
  winsorIncludeImputed: z.boolean().optional(),
});

export function denominatorPostToJSON(
  denominatorPost: DenominatorPost,
): string {
  return JSON.stringify(DenominatorPost$outboundSchema.parse(denominatorPost));
}
export function denominatorPostFromJSON(
  jsonString: string,
): SafeParseResult<DenominatorPost, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => DenominatorPost$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'DenominatorPost' from JSON`,
  );
}
