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

import * as z from "zod/v4";
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 JsonSchema = {
  name: string;
  description?: string | null | undefined;
  schemaDefinition: { [k: string]: any };
  strict?: boolean | undefined;
};

/** @internal */
export const JsonSchema$inboundSchema: z.ZodType<JsonSchema, unknown> = z
  .object({
    name: z.string(),
    description: z.nullable(z.string()).optional(),
    schema: z.record(z.string(), z.any()),
    strict: z.boolean().optional(),
  }).transform((v) => {
    return remap$(v, {
      "schema": "schemaDefinition",
    });
  });
/** @internal */
export type JsonSchema$Outbound = {
  name: string;
  description?: string | null | undefined;
  schema: { [k: string]: any };
  strict?: boolean | undefined;
};

/** @internal */
export const JsonSchema$outboundSchema: z.ZodType<
  JsonSchema$Outbound,
  JsonSchema
> = z.object({
  name: z.string(),
  description: z.nullable(z.string()).optional(),
  schemaDefinition: z.record(z.string(), z.any()),
  strict: z.boolean().optional(),
}).transform((v) => {
  return remap$(v, {
    schemaDefinition: "schema",
  });
});

export function jsonSchemaToJSON(jsonSchema: JsonSchema): string {
  return JSON.stringify(JsonSchema$outboundSchema.parse(jsonSchema));
}
export function jsonSchemaFromJSON(
  jsonString: string,
): SafeParseResult<JsonSchema, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => JsonSchema$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'JsonSchema' from JSON`,
  );
}
