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

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import { Roles, Roles$inboundSchema } from "./roles.js";

/**
 * Information on a single message included in a tokenized prompt as part of an InstructRequest.
 */
export type MessageTokens = {
  role: Roles;
  totalTokens?: number | null | undefined;
  truncated: boolean;
  usageCount: number;
};

/** @internal */
export const MessageTokens$inboundSchema: z.ZodType<MessageTokens, unknown> = z
  .object({
    role: Roles$inboundSchema,
    total_tokens: z.nullable(z.int()).optional(),
    truncated: z.boolean().default(false),
    usage_count: z.int().default(1),
  }).transform((v) => {
    return remap$(v, {
      "total_tokens": "totalTokens",
      "usage_count": "usageCount",
    });
  });

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