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

import * as z from "zod/v3";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export type Clause = {
  id?: string | undefined;
  attribute: string;
  op: string;
  values: Array<any>;
  contextKind?: string | undefined;
  negate: boolean;
};

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

/** @internal */
export const Clause$outboundSchema: z.ZodType<
  Clause$Outbound,
  z.ZodTypeDef,
  Clause
> = z.object({
  id: z.string().optional(),
  attribute: z.string(),
  op: z.string(),
  values: z.array(z.any()),
  contextKind: z.string().optional(),
  negate: z.boolean(),
}).transform((v) => {
  return remap$(v, {
    id: "_id",
  });
});

export function clauseToJSON(clause: Clause): string {
  return JSON.stringify(Clause$outboundSchema.parse(clause));
}
export function clauseFromJSON(
  jsonString: string,
): SafeParseResult<Clause, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Clause$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Clause' from JSON`,
  );
}
