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

import * as z from "zod/v4";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { smartUnion } from "../../types/smartUnion.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  TempoTraceAttributeArrayValue,
  TempoTraceAttributeArrayValue$inboundSchema,
} from "./tempotraceattributearrayvalue.js";
import {
  TempoTraceAttributeBoolValue,
  TempoTraceAttributeBoolValue$inboundSchema,
} from "./tempotraceattributeboolvalue.js";
import {
  TempoTraceAttributeIntValue,
  TempoTraceAttributeIntValue$inboundSchema,
} from "./tempotraceattributeintvalue.js";
import {
  TempoTraceAttributeStringValue,
  TempoTraceAttributeStringValue$inboundSchema,
} from "./tempotraceattributestringvalue.js";

/**
 * The value of the attribute
 */
export type TempoTraceAttributeValue =
  | TempoTraceAttributeStringValue
  | TempoTraceAttributeIntValue
  | TempoTraceAttributeBoolValue
  | TempoTraceAttributeArrayValue;

export type TempoTraceAttribute = {
  /**
   * The key of the attribute
   */
  key: string;
  /**
   * The value of the attribute
   */
  value:
    | TempoTraceAttributeStringValue
    | TempoTraceAttributeIntValue
    | TempoTraceAttributeBoolValue
    | TempoTraceAttributeArrayValue;
};

/** @internal */
export const TempoTraceAttributeValue$inboundSchema: z.ZodType<
  TempoTraceAttributeValue,
  unknown
> = smartUnion([
  TempoTraceAttributeStringValue$inboundSchema,
  TempoTraceAttributeIntValue$inboundSchema,
  TempoTraceAttributeBoolValue$inboundSchema,
  TempoTraceAttributeArrayValue$inboundSchema,
]);

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

/** @internal */
export const TempoTraceAttribute$inboundSchema: z.ZodType<
  TempoTraceAttribute,
  unknown
> = z.object({
  key: z.string(),
  value: smartUnion([
    TempoTraceAttributeStringValue$inboundSchema,
    TempoTraceAttributeIntValue$inboundSchema,
    TempoTraceAttributeBoolValue$inboundSchema,
    TempoTraceAttributeArrayValue$inboundSchema,
  ]),
});

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