/*
 * 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 EventFilter = {
  /**
   * Filter type. One of [contextAttribute, eventProperty, group]
   */
  type: string;
  /**
   * If not a group node, the context attribute name or event property name to filter on
   */
  attribute?: string | undefined;
  op: string;
  /**
   * The context attribute / event property values or group member nodes. Numeric values must not exceed 14 decimal places.
   */
  values: Array<any>;
  /**
   * For context attribute filters, the context kind.
   */
  contextKind?: string | undefined;
  /**
   * If set, then take the inverse of the operator. 'in' becomes 'not in'.
   */
  negate: boolean;
};

/** @internal */
export const EventFilter$inboundSchema: z.ZodType<
  EventFilter,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: z.string(),
  attribute: z.string().optional(),
  op: z.string(),
  values: z.array(z.any()),
  contextKind: z.string().optional(),
  negate: z.boolean(),
});
/** @internal */
export type EventFilter$Outbound = {
  type: string;
  attribute?: string | undefined;
  op: string;
  values: Array<any>;
  contextKind?: string | undefined;
  negate: boolean;
};

/** @internal */
export const EventFilter$outboundSchema: z.ZodType<
  EventFilter$Outbound,
  z.ZodTypeDef,
  EventFilter
> = z.object({
  type: z.string(),
  attribute: z.string().optional(),
  op: z.string(),
  values: z.array(z.any()),
  contextKind: z.string().optional(),
  negate: z.boolean(),
});

export function eventFilterToJSON(eventFilter: EventFilter): string {
  return JSON.stringify(EventFilter$outboundSchema.parse(eventFilter));
}
export function eventFilterFromJSON(
  jsonString: string,
): SafeParseResult<EventFilter, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => EventFilter$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'EventFilter' from JSON`,
  );
}
