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

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { smartUnion } from "../../types/smartUnion.js";
import {
  EncodedPayloadOptions,
  EncodedPayloadOptions$outboundSchema,
} from "./encodedpayloadoptions.js";

export type SignalInvocationBodyNetworkEncodedInput = {
  /**
   * The encoded payload
   */
  b64payload: string;
  /**
   * The encoding of the payload
   */
  encodingOptions?: Array<EncodedPayloadOptions> | undefined;
  /**
   * Whether the payload is empty
   */
  empty?: boolean | undefined;
  [additionalProperties: string]: unknown;
};

/**
 * Input data for the signal, matching its schema
 */
export type SignalInvocationBodyInput =
  | SignalInvocationBodyNetworkEncodedInput
  | { [k: string]: any };

export type SignalInvocationBody = {
  /**
   * The name of the signal to send
   */
  name: string;
  /**
   * Input data for the signal, matching its schema
   */
  input?:
    | SignalInvocationBodyNetworkEncodedInput
    | { [k: string]: any }
    | null
    | undefined;
};

/** @internal */
export type SignalInvocationBodyNetworkEncodedInput$Outbound = {
  b64payload: string;
  encoding_options?: Array<string> | undefined;
  empty: boolean;
  [additionalProperties: string]: unknown;
};

/** @internal */
export const SignalInvocationBodyNetworkEncodedInput$outboundSchema: z.ZodType<
  SignalInvocationBodyNetworkEncodedInput$Outbound,
  SignalInvocationBodyNetworkEncodedInput
> = z.object({
  b64payload: z.string(),
  encodingOptions: z.array(EncodedPayloadOptions$outboundSchema).optional(),
  empty: z.boolean().default(false),
}).catchall(z.any()).transform((v) => {
  return {
    ...remap$(v, {
      encodingOptions: "encoding_options",
    }),
  };
});

export function signalInvocationBodyNetworkEncodedInputToJSON(
  signalInvocationBodyNetworkEncodedInput:
    SignalInvocationBodyNetworkEncodedInput,
): string {
  return JSON.stringify(
    SignalInvocationBodyNetworkEncodedInput$outboundSchema.parse(
      signalInvocationBodyNetworkEncodedInput,
    ),
  );
}

/** @internal */
export type SignalInvocationBodyInput$Outbound =
  | SignalInvocationBodyNetworkEncodedInput$Outbound
  | { [k: string]: any };

/** @internal */
export const SignalInvocationBodyInput$outboundSchema: z.ZodType<
  SignalInvocationBodyInput$Outbound,
  SignalInvocationBodyInput
> = smartUnion([
  z.lazy(() => SignalInvocationBodyNetworkEncodedInput$outboundSchema),
  z.record(z.string(), z.any()),
]);

export function signalInvocationBodyInputToJSON(
  signalInvocationBodyInput: SignalInvocationBodyInput,
): string {
  return JSON.stringify(
    SignalInvocationBodyInput$outboundSchema.parse(signalInvocationBodyInput),
  );
}

/** @internal */
export type SignalInvocationBody$Outbound = {
  name: string;
  input?:
    | SignalInvocationBodyNetworkEncodedInput$Outbound
    | { [k: string]: any }
    | null
    | undefined;
};

/** @internal */
export const SignalInvocationBody$outboundSchema: z.ZodType<
  SignalInvocationBody$Outbound,
  SignalInvocationBody
> = z.object({
  name: z.string(),
  input: z.nullable(
    smartUnion([
      z.lazy(() => SignalInvocationBodyNetworkEncodedInput$outboundSchema),
      z.record(z.string(), z.any()),
    ]),
  ).optional(),
});

export function signalInvocationBodyToJSON(
  signalInvocationBody: SignalInvocationBody,
): string {
  return JSON.stringify(
    SignalInvocationBody$outboundSchema.parse(signalInvocationBody),
  );
}
