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

import * as z from "zod/v3";
import { remap as remap$ } from "../../lib/primitives.js";
import {
  collectExtraKeys as collectExtraKeys$,
  safeParse,
} from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import { Annotations, Annotations$inboundSchema } from "./annotations.js";
import { MCPServerIcon, MCPServerIcon$inboundSchema } from "./mcpservericon.js";

/**
 * A resource that the server is capable of reading, included in a prompt or tool call result.
 *
 * @remarks
 *
 * Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests.
 */
export type ResourceLink = {
  name: string;
  title?: string | null | undefined;
  uri: string;
  description?: string | null | undefined;
  mimeType?: string | null | undefined;
  size?: number | null | undefined;
  icons?: Array<MCPServerIcon> | null | undefined;
  annotations?: Annotations | null | undefined;
  meta?: { [k: string]: any } | null | undefined;
  type?: "resource_link" | undefined;
  additionalProperties?: { [k: string]: any } | undefined;
};

/** @internal */
export const ResourceLink$inboundSchema: z.ZodType<
  ResourceLink,
  z.ZodTypeDef,
  unknown
> = collectExtraKeys$(
  z.object({
    name: z.string(),
    title: z.nullable(z.string()).optional(),
    uri: z.string(),
    description: z.nullable(z.string()).optional(),
    mimeType: z.nullable(z.string()).optional(),
    size: z.nullable(z.number().int()).optional(),
    icons: z.nullable(z.array(MCPServerIcon$inboundSchema)).optional(),
    annotations: z.nullable(Annotations$inboundSchema).optional(),
    _meta: z.nullable(z.record(z.any())).optional(),
    type: z.literal("resource_link").default("resource_link").optional(),
  }).catchall(z.any()),
  "additionalProperties",
  true,
).transform((v) => {
  return remap$(v, {
    "_meta": "meta",
  });
});

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