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

export type MetricInput = {
  /**
   * The metric key
   */
  key: string;
  /**
   * Whether this is a metric group (true) or a metric (false). Defaults to false
   */
  isGroup?: boolean | undefined;
  /**
   * Deprecated, use <code>primarySingleMetricKey</code> and <code>primaryFunnelKey</code>. Whether this is a primary metric (true) or a secondary metric (false)
   *
   * @deprecated field: This will be removed in a future release, please migrate away from it as soon as possible.
   */
  primary?: boolean | undefined;
  /**
   * The analysis unit to use for this metric. If omitted, analysis uses the iteration's randomization unit.
   */
  analysisUnit?: string | undefined;
};

/** @internal */
export const MetricInput$inboundSchema: z.ZodType<
  MetricInput,
  z.ZodTypeDef,
  unknown
> = z.object({
  key: z.string(),
  isGroup: z.boolean().optional(),
  primary: z.boolean().optional(),
  analysisUnit: z.string().optional(),
});
/** @internal */
export type MetricInput$Outbound = {
  key: string;
  isGroup?: boolean | undefined;
  primary?: boolean | undefined;
  analysisUnit?: string | undefined;
};

/** @internal */
export const MetricInput$outboundSchema: z.ZodType<
  MetricInput$Outbound,
  z.ZodTypeDef,
  MetricInput
> = z.object({
  key: z.string(),
  isGroup: z.boolean().optional(),
  primary: z.boolean().optional(),
  analysisUnit: z.string().optional(),
});

export function metricInputToJSON(metricInput: MetricInput): string {
  return JSON.stringify(MetricInput$outboundSchema.parse(metricInput));
}
export function metricInputFromJSON(
  jsonString: string,
): SafeParseResult<MetricInput, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => MetricInput$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'MetricInput' from JSON`,
  );
}
