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

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";
import {
  ModerationLlmv1Config,
  ModerationLlmv1Config$inboundSchema,
  ModerationLlmv1Config$Outbound,
  ModerationLlmv1Config$outboundSchema,
} from "./moderationllmv1config.js";

export type GuardrailConfig = {
  /**
   * If true, return HTTP 403 and block request in the event of a server-side error
   */
  blockOnError?: boolean | undefined;
  moderationLlmV1: ModerationLlmv1Config | null;
};

/** @internal */
export const GuardrailConfig$inboundSchema: z.ZodType<
  GuardrailConfig,
  z.ZodTypeDef,
  unknown
> = z.object({
  block_on_error: z.boolean().default(false),
  moderation_llm_v1: z.nullable(ModerationLlmv1Config$inboundSchema),
}).transform((v) => {
  return remap$(v, {
    "block_on_error": "blockOnError",
    "moderation_llm_v1": "moderationLlmV1",
  });
});
/** @internal */
export type GuardrailConfig$Outbound = {
  block_on_error: boolean;
  moderation_llm_v1: ModerationLlmv1Config$Outbound | null;
};

/** @internal */
export const GuardrailConfig$outboundSchema: z.ZodType<
  GuardrailConfig$Outbound,
  z.ZodTypeDef,
  GuardrailConfig
> = z.object({
  blockOnError: z.boolean().default(false),
  moderationLlmV1: z.nullable(ModerationLlmv1Config$outboundSchema),
}).transform((v) => {
  return remap$(v, {
    blockOnError: "block_on_error",
    moderationLlmV1: "moderation_llm_v1",
  });
});

export function guardrailConfigToJSON(
  guardrailConfig: GuardrailConfig,
): string {
  return JSON.stringify(GuardrailConfig$outboundSchema.parse(guardrailConfig));
}
export function guardrailConfigFromJSON(
  jsonString: string,
): SafeParseResult<GuardrailConfig, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => GuardrailConfig$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'GuardrailConfig' from JSON`,
  );
}
