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

import * as z from "zod/v3";
import { remap as remap$ } from "../../lib/primitives.js";
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 Two =
  | (AssistantMessage & { role: "assistant" })
  | (SystemMessage & { role: "system" })
  | (ToolMessage & { role: "tool" })
  | (UserMessage & { role: "user" });

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

/**
 * Chat to classify
 */
export type ChatModerationRequestInputs =
  | Array<
    | (AssistantMessage & { role: "assistant" })
    | (SystemMessage & { role: "system" })
    | (ToolMessage & { role: "tool" })
    | (UserMessage & { role: "user" })
  >
  | Array<
    Array<
      | (AssistantMessage & { role: "assistant" })
      | (SystemMessage & { role: "system" })
      | (ToolMessage & { role: "tool" })
      | (UserMessage & { role: "user" })
    >
  >;

export type ChatModerationRequest = {
  /**
   * Chat to classify
   */
  inputs:
    | Array<
      | (AssistantMessage & { role: "assistant" })
      | (SystemMessage & { role: "system" })
      | (ToolMessage & { role: "tool" })
      | (UserMessage & { role: "user" })
    >
    | Array<
      Array<
        | (AssistantMessage & { role: "assistant" })
        | (SystemMessage & { role: "system" })
        | (ToolMessage & { role: "tool" })
        | (UserMessage & { role: "user" })
      >
    >;
  model: string;
};

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

/** @internal */
export const Two$outboundSchema: z.ZodType<Two$Outbound, z.ZodTypeDef, Two> = 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 twoToJSON(two: Two): string {
  return JSON.stringify(Two$outboundSchema.parse(two));
}

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

/** @internal */
export const One$outboundSchema: z.ZodType<One$Outbound, z.ZodTypeDef, One> = 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 oneToJSON(one: One): string {
  return JSON.stringify(One$outboundSchema.parse(one));
}

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

/** @internal */
export const ChatModerationRequestInputs$outboundSchema: z.ZodType<
  ChatModerationRequestInputs$Outbound,
  z.ZodTypeDef,
  ChatModerationRequestInputs
> = z.union([
  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") })),
    ]),
  ),
  z.array(
    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 chatModerationRequestInputsToJSON(
  chatModerationRequestInputs: ChatModerationRequestInputs,
): string {
  return JSON.stringify(
    ChatModerationRequestInputs$outboundSchema.parse(
      chatModerationRequestInputs,
    ),
  );
}

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

/** @internal */
export const ChatModerationRequest$outboundSchema: z.ZodType<
  ChatModerationRequest$Outbound,
  z.ZodTypeDef,
  ChatModerationRequest
> = z.object({
  inputs: z.union([
    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") })),
      ]),
    ),
    z.array(
      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") })),
        ]),
      ),
    ),
  ]),
  model: z.string(),
}).transform((v) => {
  return remap$(v, {
    inputs: "input",
  });
});

export function chatModerationRequestToJSON(
  chatModerationRequest: ChatModerationRequest,
): string {
  return JSON.stringify(
    ChatModerationRequest$outboundSchema.parse(chatModerationRequest),
  );
}
