/*
 * 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";

export type Link = {
  href?: string | undefined;
  type?: string | undefined;
};

/** @internal */
export const Link$inboundSchema: z.ZodType<Link, z.ZodTypeDef, unknown> = z
  .object({
    href: z.string().optional(),
    type: z.string().optional(),
  });
/** @internal */
export type Link$Outbound = {
  href?: string | undefined;
  type?: string | undefined;
};

/** @internal */
export const Link$outboundSchema: z.ZodType<Link$Outbound, z.ZodTypeDef, Link> =
  z.object({
    href: z.string().optional(),
    type: z.string().optional(),
  });

export function linkToJSON(link: Link): string {
  return JSON.stringify(Link$outboundSchema.parse(link));
}
export function linkFromJSON(
  jsonString: string,
): SafeParseResult<Link, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Link$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Link' from JSON`,
  );
}
