/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 * @generated-id: 4374f7f8136c
 */

import * as z from "zod/v4";
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 Op = {
  Lt: "lt",
  Lte: "lte",
  Gt: "gt",
  Gte: "gte",
  Startswith: "startswith",
  Istartswith: "istartswith",
  Endswith: "endswith",
  Iendswith: "iendswith",
  Contains: "contains",
  Icontains: "icontains",
  Matches: "matches",
  Notcontains: "notcontains",
  Inotcontains: "inotcontains",
  Eq: "eq",
  Neq: "neq",
  Isnull: "isnull",
  Includes: "includes",
  Excludes: "excludes",
  LenEq: "len_eq",
} as const;
export type Op = OpenEnum<typeof Op>;

export type FilterCondition = {
  field: string;
  op: Op;
  value: any;
};

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

/** @internal */
export const FilterCondition$inboundSchema: z.ZodType<
  FilterCondition,
  unknown
> = z.object({
  field: z.string(),
  op: Op$inboundSchema,
  value: z.any(),
});
/** @internal */
export type FilterCondition$Outbound = {
  field: string;
  op: string;
  value: any;
};

/** @internal */
export const FilterCondition$outboundSchema: z.ZodType<
  FilterCondition$Outbound,
  FilterCondition
> = z.object({
  field: z.string(),
  op: Op$outboundSchema,
  value: z.any(),
});

export function filterConditionToJSON(
  filterCondition: FilterCondition,
): string {
  return JSON.stringify(FilterCondition$outboundSchema.parse(filterCondition));
}
export function filterConditionFromJSON(
  jsonString: string,
): SafeParseResult<FilterCondition, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => FilterCondition$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'FilterCondition' from JSON`,
  );
}
