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

import * as z from "zod/v3";
import {
  AssistantMessage,
  AssistantMessage$Outbound,
  AssistantMessage$outboundSchema,
} from "./assistantmessage.js";
import {
  SystemMessage,
  SystemMessage$Outbound,
  SystemMessage$outboundSchema,
} from "./systemmessage.js";
import {
  ToolMessage,
  ToolMessage$Outbound,
  ToolMessage$outboundSchema,
} from "./toolmessage.js";
import {
  UserMessage,
  UserMessage$Outbound,
  UserMessage$outboundSchema,
} from "./usermessage.js";

export type InstructRequestMessages =
  | (AssistantMessage & { role: "assistant" })
  | (SystemMessage & { role: "system" })
  | (ToolMessage & { role: "tool" })
  | (UserMessage & { role: "user" });

export type InstructRequest = {
  messages: Array<
    | (AssistantMessage & { role: "assistant" })
    | (SystemMessage & { role: "system" })
    | (ToolMessage & { role: "tool" })
    | (UserMessage & { role: "user" })
  >;
};

/** @internal */
export type InstructRequestMessages$Outbound =
  | (AssistantMessage$Outbound & { role: "assistant" })
  | (SystemMessage$Outbound & { role: "system" })
  | (ToolMessage$Outbound & { role: "tool" })
  | (UserMessage$Outbound & { role: "user" });

/** @internal */
export const InstructRequestMessages$outboundSchema: z.ZodType<
  InstructRequestMessages$Outbound,
  z.ZodTypeDef,
  InstructRequestMessages
> = z.union([
  AssistantMessage$outboundSchema.and(
    z.object({ role: z.literal("assistant") }),
  ),
  SystemMessage$outboundSchema.and(z.object({ role: z.literal("system") })),
  ToolMessage$outboundSchema.and(z.object({ role: z.literal("tool") })),
  UserMessage$outboundSchema.and(z.object({ role: z.literal("user") })),
]);

export function instructRequestMessagesToJSON(
  instructRequestMessages: InstructRequestMessages,
): string {
  return JSON.stringify(
    InstructRequestMessages$outboundSchema.parse(instructRequestMessages),
  );
}

/** @internal */
export type InstructRequest$Outbound = {
  messages: Array<
    | (AssistantMessage$Outbound & { role: "assistant" })
    | (SystemMessage$Outbound & { role: "system" })
    | (ToolMessage$Outbound & { role: "tool" })
    | (UserMessage$Outbound & { role: "user" })
  >;
};

/** @internal */
export const InstructRequest$outboundSchema: z.ZodType<
  InstructRequest$Outbound,
  z.ZodTypeDef,
  InstructRequest
> = z.object({
  messages: z.array(
    z.union([
      AssistantMessage$outboundSchema.and(
        z.object({ role: z.literal("assistant") }),
      ),
      SystemMessage$outboundSchema.and(z.object({ role: z.literal("system") })),
      ToolMessage$outboundSchema.and(z.object({ role: z.literal("tool") })),
      UserMessage$outboundSchema.and(z.object({ role: z.literal("user") })),
    ]),
  ),
});

export function instructRequestToJSON(
  instructRequest: InstructRequest,
): string {
  return JSON.stringify(InstructRequest$outboundSchema.parse(instructRequest));
}
