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

import * as z from "zod/v4-mini";
import { safeParse } from "../../lib/schemas.js";
import * as openEnums from "../../types/enums.js";
import { OpenEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export const Func = {
  Sum: "sum",
  Max: "max",
  Min: "min",
  Avg: "avg",
} as const;
export type Func = OpenEnum<typeof Func>;

export type PropertyAggregation = {
  func: Func;
  property: string;
};

/** @internal */
export const Func$inboundSchema: z.ZodMiniType<Func, unknown> = openEnums
  .inboundSchema(Func);
/** @internal */
export const Func$outboundSchema: z.ZodMiniType<string, Func> = openEnums
  .outboundSchema(Func);

/** @internal */
export const PropertyAggregation$inboundSchema: z.ZodMiniType<
  PropertyAggregation,
  unknown
> = z.object({
  func: Func$inboundSchema,
  property: z.string(),
});
/** @internal */
export type PropertyAggregation$Outbound = {
  func: string;
  property: string;
};

/** @internal */
export const PropertyAggregation$outboundSchema: z.ZodMiniType<
  PropertyAggregation$Outbound,
  PropertyAggregation
> = z.object({
  func: Func$outboundSchema,
  property: z.string(),
});

export function propertyAggregationToJSON(
  propertyAggregation: PropertyAggregation,
): string {
  return JSON.stringify(
    PropertyAggregation$outboundSchema.parse(propertyAggregation),
  );
}
export function propertyAggregationFromJSON(
  jsonString: string,
): SafeParseResult<PropertyAggregation, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => PropertyAggregation$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'PropertyAggregation' from JSON`,
  );
}
