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

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 QueryDefinition = {
  /**
   * Name of the query
   */
  name: string;
  /**
   * Description of the query
   */
  description?: string | null | undefined;
  /**
   * Input JSON schema of the query's model
   */
  inputSchema: { [k: string]: any };
  /**
   * Output JSON schema of the query's model
   */
  outputSchema?: { [k: string]: any } | null | undefined;
};

/** @internal */
export const QueryDefinition$inboundSchema: z.ZodType<
  QueryDefinition,
  unknown
> = z.object({
  name: z.string(),
  description: z.nullable(z.string()).optional(),
  input_schema: z.record(z.string(), z.any()),
  output_schema: z.nullable(z.record(z.string(), z.any())).optional(),
}).transform((v) => {
  return remap$(v, {
    "input_schema": "inputSchema",
    "output_schema": "outputSchema",
  });
});

export function queryDefinitionFromJSON(
  jsonString: string,
): SafeParseResult<QueryDefinition, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => QueryDefinition$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'QueryDefinition' from JSON`,
  );
}
