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

import * as z from "zod/v3";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  PatchOperation,
  PatchOperation$inboundSchema,
  PatchOperation$Outbound,
  PatchOperation$outboundSchema,
} from "./patchoperation.js";

export type PatchWithComment = {
  patch: Array<PatchOperation>;
  /**
   * Optional comment
   */
  comment?: string | undefined;
};

/** @internal */
export const PatchWithComment$inboundSchema: z.ZodType<
  PatchWithComment,
  z.ZodTypeDef,
  unknown
> = z.object({
  patch: z.array(PatchOperation$inboundSchema),
  comment: z.string().optional(),
});
/** @internal */
export type PatchWithComment$Outbound = {
  patch: Array<PatchOperation$Outbound>;
  comment?: string | undefined;
};

/** @internal */
export const PatchWithComment$outboundSchema: z.ZodType<
  PatchWithComment$Outbound,
  z.ZodTypeDef,
  PatchWithComment
> = z.object({
  patch: z.array(PatchOperation$outboundSchema),
  comment: z.string().optional(),
});

export function patchWithCommentToJSON(
  patchWithComment: PatchWithComment,
): string {
  return JSON.stringify(
    PatchWithComment$outboundSchema.parse(patchWithComment),
  );
}
export function patchWithCommentFromJSON(
  jsonString: string,
): SafeParseResult<PatchWithComment, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => PatchWithComment$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'PatchWithComment' from JSON`,
  );
}
