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

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

/**
 * Text content for a message.
 */
export type TextContent = {
  type?: "text" | undefined;
  text: string;
  annotations?: Annotations | null | undefined;
  meta?: { [k: string]: any } | null | undefined;
  additionalProperties?: { [k: string]: any } | undefined;
};

/** @internal */
export const TextContent$inboundSchema: z.ZodType<
  TextContent,
  z.ZodTypeDef,
  unknown
> = collectExtraKeys$(
  z.object({
    type: z.literal("text").default("text").optional(),
    text: z.string(),
    annotations: z.nullable(Annotations$inboundSchema).optional(),
    _meta: z.nullable(z.record(z.any())).optional(),
  }).catchall(z.any()),
  "additionalProperties",
  true,
).transform((v) => {
  return remap$(v, {
    "_meta": "meta",
  });
});

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