/*
 * 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 {
  HunkRep,
  HunkRep$inboundSchema,
  HunkRep$Outbound,
  HunkRep$outboundSchema,
} from "./hunkrep.js";

export type ReferenceRep = {
  /**
   * File path of the reference
   */
  path: string;
  /**
   * Programming language used in the file
   */
  hint?: string | undefined;
  hunks: Array<HunkRep>;
};

/** @internal */
export const ReferenceRep$inboundSchema: z.ZodType<
  ReferenceRep,
  z.ZodTypeDef,
  unknown
> = z.object({
  path: z.string(),
  hint: z.string().optional(),
  hunks: z.array(HunkRep$inboundSchema),
});
/** @internal */
export type ReferenceRep$Outbound = {
  path: string;
  hint?: string | undefined;
  hunks: Array<HunkRep$Outbound>;
};

/** @internal */
export const ReferenceRep$outboundSchema: z.ZodType<
  ReferenceRep$Outbound,
  z.ZodTypeDef,
  ReferenceRep
> = z.object({
  path: z.string(),
  hint: z.string().optional(),
  hunks: z.array(HunkRep$outboundSchema),
});

export function referenceRepToJSON(referenceRep: ReferenceRep): string {
  return JSON.stringify(ReferenceRep$outboundSchema.parse(referenceRep));
}
export function referenceRepFromJSON(
  jsonString: string,
): SafeParseResult<ReferenceRep, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ReferenceRep$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ReferenceRep' from JSON`,
  );
}
