//!
//! AUTO-GENERATED CODE - DO NOT EDIT!
//!
//! Union Serialization Test API
//! Source: crates/oas3-gen/fixtures/union_serde.json
//! Version: 1.0.0
//! Generated by `oas3-gen v0.26.0`
//!
//! Comprehensive test fixture for union serialization/deserialization

use serde::{Deserialize, Serialize};
use validator::Validate;
#[serde_with::skip_serializing_none]
#[derive(Debug, Clone, PartialEq, Serialize, oas3_gen_support::Default, bon::Builder)]
pub struct ContentRequest {
  pub blocks: Vec<ContentBlock>,
  /// Flexible metadata that can be string or object
  pub metadata: Option<Metadata>,
}
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default, bon::Builder)]
pub struct ContentResponse {
  pub id: String,
  /// A union of content block types with discriminator
  pub content: Box<ContentBlock>,
  pub usage: Option<Usage>,
}
/// A union of content block types with discriminator
#[derive(Debug, Clone, PartialEq)]
pub enum ContentBlock {
  Text(TextBlock),
  Image(ImageBlock),
  Code(CodeBlock),
  ToolUse(ToolUseBlock),
  ToolResult(ToolResultBlock),
}
impl ContentBlock {
  pub const DISCRIMINATOR_FIELD: &'static str = "type";
}
impl Default for ContentBlock {
  fn default() -> Self {
    Self::Text(<TextBlock>::default())
  }
}
impl serde::Serialize for ContentBlock {
  fn serialize<S>(&self, serializer: S) -> core::result::Result<S::Ok, S::Error>
  where
    S: serde::Serializer,
  {
    match self {
      Self::Text(v) => v.serialize(serializer),
      Self::Image(v) => v.serialize(serializer),
      Self::Code(v) => v.serialize(serializer),
      Self::ToolUse(v) => v.serialize(serializer),
      Self::ToolResult(v) => v.serialize(serializer),
    }
  }
}
impl<'de> serde::Deserialize<'de> for ContentBlock {
  fn deserialize<D>(deserializer: D) -> core::result::Result<Self, D::Error>
  where
    D: serde::Deserializer<'de>,
  {
    let value = serde_json::Value::deserialize(deserializer)?;
    match value.get(Self::DISCRIMINATOR_FIELD).and_then(|v| v.as_str()) {
      Some("text") => serde_json::from_value(value)
        .map(Self::Text)
        .map_err(serde::de::Error::custom),
      Some("image") => serde_json::from_value(value)
        .map(Self::Image)
        .map_err(serde::de::Error::custom),
      Some("code") => serde_json::from_value(value)
        .map(Self::Code)
        .map_err(serde::de::Error::custom),
      Some("tool_use") => serde_json::from_value(value)
        .map(Self::ToolUse)
        .map_err(serde::de::Error::custom),
      Some("tool_result") => serde_json::from_value(value)
        .map(Self::ToolResult)
        .map_err(serde::de::Error::custom),
      None => Err(serde::de::Error::missing_field(Self::DISCRIMINATOR_FIELD)),
      Some(other) => Err(serde::de::Error::custom(format!(
        "Unknown discriminator value '{}' for field '{}'",
        other, "type"
      ))),
    }
  }
}
impl ContentBlock {
  pub fn text(text: String) -> Self {
    Self::Text(TextBlock {
      text,
      ..Default::default()
    })
  }
  pub fn image(source: Box<ImageSource>) -> Self {
    Self::Image(ImageBlock {
      source,
      ..Default::default()
    })
  }
  pub fn code(code: String) -> Self {
    Self::Code(CodeBlock {
      code,
      ..Default::default()
    })
  }
}
#[serde_with::skip_serializing_none]
#[derive(
  Debug, Clone, PartialEq, Serialize, Deserialize, validator::Validate, oas3_gen_support::Default, bon::Builder,
)]
#[serde(default)]
pub struct TextBlock {
  #[doc(hidden)]
  #[serde(default, rename = "type", skip_deserializing)]
  #[default(Some("text"))]
  #[builder(skip = Some("text"))]
  pub r#type: Option<&'static str>,
  #[validate(length(min = 1u64))]
  pub text: String,
  pub annotations: Option<Vec<Annotation>>,
  pub recipes: Option<Vec<RecipeList>>,
}
#[serde_with::skip_serializing_none]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, oas3_gen_support::Default, bon::Builder)]
#[serde(default)]
pub struct ImageBlock {
  #[doc(hidden)]
  #[serde(default, rename = "type", skip_deserializing)]
  #[default(Some("image"))]
  #[builder(skip = Some("image"))]
  pub r#type: Option<&'static str>,
  /// Image source can be base64 or URL
  pub source: Box<ImageSource>,
  pub alt_text: Option<String>,
}
#[serde_with::skip_serializing_none]
#[derive(
  Debug, Clone, PartialEq, Serialize, Deserialize, validator::Validate, oas3_gen_support::Default, bon::Builder,
)]
#[serde(default)]
pub struct CodeBlock {
  #[doc(hidden)]
  #[serde(default, rename = "type", skip_deserializing)]
  #[default(Some("code"))]
  #[builder(skip = Some("code"))]
  pub r#type: Option<&'static str>,
  #[validate(length(min = 1u64))]
  pub code: String,
  pub language: Option<String>,
}
#[serde_with::skip_serializing_none]
#[derive(
  Debug, Clone, PartialEq, Serialize, Deserialize, validator::Validate, oas3_gen_support::Default, bon::Builder,
)]
#[serde(default)]
pub struct ToolUseBlock {
  #[doc(hidden)]
  #[serde(default, rename = "type", skip_deserializing)]
  #[default(Some("tool_use"))]
  #[builder(skip = Some("tool_use"))]
  pub r#type: Option<&'static str>,
  #[validate(length(min = 1u64))]
  pub id: String,
  #[validate(length(min = 1u64))]
  pub name: String,
  pub input: indexmap::IndexMap<String, serde_json::Value>,
}
#[serde_with::skip_serializing_none]
#[derive(
  Debug, Clone, PartialEq, Serialize, Deserialize, validator::Validate, oas3_gen_support::Default, bon::Builder,
)]
#[serde(default)]
pub struct ToolResultBlock {
  #[doc(hidden)]
  #[serde(default, rename = "type", skip_deserializing)]
  #[default(Some("tool_result"))]
  #[builder(skip = Some("tool_result"))]
  pub r#type: Option<&'static str>,
  #[validate(length(min = 1u64))]
  pub tool_use_id: String,
  /// Tool result can be text or array of content blocks
  pub content: ToolResultContent,
  pub iterations: Option<UsageCounters>,
  pub is_error: Option<bool>,
}
/// Tool result can be text or array of content blocks
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, oas3_gen_support::Default)]
#[serde(untagged)]
pub enum ToolResultContent {
  #[default]
  String(String),
  Array(Vec<ToolResultContentBlock>),
}
#[derive(Debug, Clone, PartialEq)]
pub enum ToolResultContentBlock {
  Text(TextBlock),
  Image(ImageBlock),
}
impl ToolResultContentBlock {
  pub const DISCRIMINATOR_FIELD: &'static str = "type";
}
impl Default for ToolResultContentBlock {
  fn default() -> Self {
    Self::Text(<TextBlock>::default())
  }
}
impl serde::Serialize for ToolResultContentBlock {
  fn serialize<S>(&self, serializer: S) -> core::result::Result<S::Ok, S::Error>
  where
    S: serde::Serializer,
  {
    match self {
      Self::Text(v) => v.serialize(serializer),
      Self::Image(v) => v.serialize(serializer),
    }
  }
}
impl<'de> serde::Deserialize<'de> for ToolResultContentBlock {
  fn deserialize<D>(deserializer: D) -> core::result::Result<Self, D::Error>
  where
    D: serde::Deserializer<'de>,
  {
    let value = serde_json::Value::deserialize(deserializer)?;
    match value.get(Self::DISCRIMINATOR_FIELD).and_then(|v| v.as_str()) {
      Some("text") => serde_json::from_value(value)
        .map(Self::Text)
        .map_err(serde::de::Error::custom),
      Some("image") => serde_json::from_value(value)
        .map(Self::Image)
        .map_err(serde::de::Error::custom),
      None => Err(serde::de::Error::missing_field(Self::DISCRIMINATOR_FIELD)),
      Some(other) => Err(serde::de::Error::custom(format!(
        "Unknown discriminator value '{}' for field '{}'",
        other, "type"
      ))),
    }
  }
}
impl ToolResultContentBlock {
  pub fn text(text: String) -> Self {
    Self::Text(TextBlock {
      text,
      ..Default::default()
    })
  }
  pub fn image(source: Box<ImageSource>) -> Self {
    Self::Image(ImageBlock {
      source,
      ..Default::default()
    })
  }
}
/// Image source can be base64 or URL
#[derive(Debug, Clone, PartialEq)]
pub enum ImageSource {
  Base64(Base64ImageSource),
  Url(UrlImageSource),
}
impl ImageSource {
  pub const DISCRIMINATOR_FIELD: &'static str = "type";
}
impl Default for ImageSource {
  fn default() -> Self {
    Self::Base64(<Base64ImageSource>::default())
  }
}
impl serde::Serialize for ImageSource {
  fn serialize<S>(&self, serializer: S) -> core::result::Result<S::Ok, S::Error>
  where
    S: serde::Serializer,
  {
    match self {
      Self::Base64(v) => v.serialize(serializer),
      Self::Url(v) => v.serialize(serializer),
    }
  }
}
impl<'de> serde::Deserialize<'de> for ImageSource {
  fn deserialize<D>(deserializer: D) -> core::result::Result<Self, D::Error>
  where
    D: serde::Deserializer<'de>,
  {
    let value = serde_json::Value::deserialize(deserializer)?;
    match value.get(Self::DISCRIMINATOR_FIELD).and_then(|v| v.as_str()) {
      Some("base64") => serde_json::from_value(value)
        .map(Self::Base64)
        .map_err(serde::de::Error::custom),
      Some("url") => serde_json::from_value(value)
        .map(Self::Url)
        .map_err(serde::de::Error::custom),
      None => Err(serde::de::Error::missing_field(Self::DISCRIMINATOR_FIELD)),
      Some(other) => Err(serde::de::Error::custom(format!(
        "Unknown discriminator value '{}' for field '{}'",
        other, "type"
      ))),
    }
  }
}
impl ImageSource {
  pub fn url(url: String) -> Self {
    Self::Url(UrlImageSource {
      url,
      ..Default::default()
    })
  }
}
#[serde_with::serde_as]
#[serde_with::skip_serializing_none]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, oas3_gen_support::Default, bon::Builder)]
#[serde(default)]
pub struct Base64ImageSource {
  #[doc(hidden)]
  #[serde(default, rename = "type", skip_deserializing)]
  #[default(Some("base64"))]
  #[builder(skip = Some("base64"))]
  pub r#type: Option<&'static str>,
  pub media_type: MediaType,
  #[serde_as(as = "serde_with::base64::Base64")]
  pub data: Vec<u8>,
}
#[serde_with::skip_serializing_none]
#[derive(
  Debug, Clone, PartialEq, Serialize, Deserialize, validator::Validate, oas3_gen_support::Default, bon::Builder,
)]
#[serde(default)]
pub struct UrlImageSource {
  #[doc(hidden)]
  #[serde(default, rename = "type", skip_deserializing)]
  #[default(Some("url"))]
  #[builder(skip = Some("url"))]
  pub r#type: Option<&'static str>,
  #[validate(url, length(min = 1u64))]
  pub url: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, oas3_gen_support::Default)]
pub enum MediaType {
  #[serde(rename = "image/jpeg")]
  #[default]
  ImageJpeg,
  #[serde(rename = "image/png")]
  ImagePng,
  #[serde(rename = "image/gif")]
  ImageGif,
  #[serde(rename = "image/webp")]
  ImageWebp,
}
impl core::fmt::Display for MediaType {
  fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    match self {
      Self::ImageJpeg => write!(f, "image/jpeg"),
      Self::ImagePng => write!(f, "image/png"),
      Self::ImageGif => write!(f, "image/gif"),
      Self::ImageWebp => write!(f, "image/webp"),
    }
  }
}
/// Text annotation with different types
#[derive(Debug, Clone, PartialEq)]
pub enum Annotation {
  Citation(CitationAnnotation),
  Link(LinkAnnotation),
}
impl Annotation {
  pub const DISCRIMINATOR_FIELD: &'static str = "type";
}
impl Default for Annotation {
  fn default() -> Self {
    Self::Citation(<CitationAnnotation>::default())
  }
}
impl serde::Serialize for Annotation {
  fn serialize<S>(&self, serializer: S) -> core::result::Result<S::Ok, S::Error>
  where
    S: serde::Serializer,
  {
    match self {
      Self::Citation(v) => v.serialize(serializer),
      Self::Link(v) => v.serialize(serializer),
    }
  }
}
impl<'de> serde::Deserialize<'de> for Annotation {
  fn deserialize<D>(deserializer: D) -> core::result::Result<Self, D::Error>
  where
    D: serde::Deserializer<'de>,
  {
    let value = serde_json::Value::deserialize(deserializer)?;
    match value.get(Self::DISCRIMINATOR_FIELD).and_then(|v| v.as_str()) {
      Some("citation") => serde_json::from_value(value)
        .map(Self::Citation)
        .map_err(serde::de::Error::custom),
      Some("link") => serde_json::from_value(value)
        .map(Self::Link)
        .map_err(serde::de::Error::custom),
      None => Err(serde::de::Error::missing_field(Self::DISCRIMINATOR_FIELD)),
      Some(other) => Err(serde::de::Error::custom(format!(
        "Unknown discriminator value '{}' for field '{}'",
        other, "type"
      ))),
    }
  }
}
#[serde_with::skip_serializing_none]
#[derive(
  Debug, Clone, PartialEq, Serialize, Deserialize, validator::Validate, oas3_gen_support::Default, bon::Builder,
)]
#[serde(default)]
pub struct CitationAnnotation {
  #[doc(hidden)]
  #[serde(default, rename = "type", skip_deserializing)]
  #[default(Some("citation"))]
  #[builder(skip = Some("citation"))]
  pub r#type: Option<&'static str>,
  pub start: i64,
  pub end: i64,
  #[validate(length(min = 1u64))]
  #[builder(name = build_value)]
  pub build: String,
}
#[serde_with::skip_serializing_none]
#[derive(
  Debug, Clone, PartialEq, Serialize, Deserialize, validator::Validate, oas3_gen_support::Default, bon::Builder,
)]
#[serde(default)]
pub struct LinkAnnotation {
  #[doc(hidden)]
  #[serde(default, rename = "type", skip_deserializing)]
  #[default(Some("link"))]
  #[builder(skip = Some("link"))]
  pub r#type: Option<&'static str>,
  pub start: i64,
  pub end: i64,
  #[validate(url, length(min = 1u64))]
  pub url: String,
}
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default, bon::Builder)]
pub struct EventList {
  pub events: Vec<Event>,
}
/// Streaming event with different types
#[derive(Debug, Clone, PartialEq)]
pub enum Event {
  MessageStart(MessageStartEvent),
  ContentBlockStart(ContentBlockStartEvent),
  ContentBlockDelta(ContentBlockDeltaEvent),
  ContentBlockStop(ContentBlockStopEvent),
  MessageStop(MessageStopEvent),
  Ping(PingEvent),
}
impl Event {
  pub const DISCRIMINATOR_FIELD: &'static str = "type";
}
impl Default for Event {
  fn default() -> Self {
    Self::MessageStart(<MessageStartEvent>::default())
  }
}
impl<'de> serde::Deserialize<'de> for Event {
  fn deserialize<D>(deserializer: D) -> core::result::Result<Self, D::Error>
  where
    D: serde::Deserializer<'de>,
  {
    let value = serde_json::Value::deserialize(deserializer)?;
    match value.get(Self::DISCRIMINATOR_FIELD).and_then(|v| v.as_str()) {
      Some("message_start") => serde_json::from_value(value)
        .map(Self::MessageStart)
        .map_err(serde::de::Error::custom),
      Some("content_block_start") => serde_json::from_value(value)
        .map(Self::ContentBlockStart)
        .map_err(serde::de::Error::custom),
      Some("content_block_delta") => serde_json::from_value(value)
        .map(Self::ContentBlockDelta)
        .map_err(serde::de::Error::custom),
      Some("content_block_stop") => serde_json::from_value(value)
        .map(Self::ContentBlockStop)
        .map_err(serde::de::Error::custom),
      Some("message_stop") => serde_json::from_value(value)
        .map(Self::MessageStop)
        .map_err(serde::de::Error::custom),
      Some("ping") => serde_json::from_value(value)
        .map(Self::Ping)
        .map_err(serde::de::Error::custom),
      None => Err(serde::de::Error::missing_field(Self::DISCRIMINATOR_FIELD)),
      Some(other) => Err(serde::de::Error::custom(format!(
        "Unknown discriminator value '{}' for field '{}'",
        other, "type"
      ))),
    }
  }
}
impl Event {
  pub fn message_start(message: Message) -> Self {
    Self::MessageStart(MessageStartEvent {
      message,
      ..Default::default()
    })
  }
  pub fn content_block_stop(index: i64) -> Self {
    Self::ContentBlockStop(ContentBlockStopEvent {
      index,
      ..Default::default()
    })
  }
  pub fn message_stop() -> Self {
    Self::MessageStop(MessageStopEvent::default())
  }
  pub fn ping() -> Self {
    Self::Ping(PingEvent::default())
  }
}
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default, bon::Builder)]
#[serde(default)]
pub struct MessageStartEvent {
  #[doc(hidden)]
  #[serde(default, rename = "type", skip_deserializing)]
  #[default(Some("message_start"))]
  #[builder(skip = Some("message_start"))]
  pub r#type: Option<&'static str>,
  pub message: Message,
}
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default, bon::Builder)]
#[serde(default)]
pub struct ContentBlockStartEvent {
  #[doc(hidden)]
  #[serde(default, rename = "type", skip_deserializing)]
  #[default(Some("content_block_start"))]
  #[builder(skip = Some("content_block_start"))]
  pub r#type: Option<&'static str>,
  pub index: i64,
  /// A union of content block types with discriminator
  pub content_block: Box<ContentBlock>,
}
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default, bon::Builder)]
#[serde(default)]
pub struct ContentBlockDeltaEvent {
  #[doc(hidden)]
  #[serde(default, rename = "type", skip_deserializing)]
  #[default(Some("content_block_delta"))]
  #[builder(skip = Some("content_block_delta"))]
  pub r#type: Option<&'static str>,
  pub index: i64,
  /// Delta content for streaming
  pub delta: Box<Delta>,
}
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default, bon::Builder)]
#[serde(default)]
pub struct ContentBlockStopEvent {
  #[doc(hidden)]
  #[serde(default, rename = "type", skip_deserializing)]
  #[default(Some("content_block_stop"))]
  #[builder(skip = Some("content_block_stop"))]
  pub r#type: Option<&'static str>,
  pub index: i64,
}
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default, bon::Builder)]
#[serde(default)]
pub struct MessageStopEvent {
  #[doc(hidden)]
  #[serde(default, rename = "type", skip_deserializing)]
  #[default(Some("message_stop"))]
  #[builder(skip = Some("message_stop"))]
  pub r#type: Option<&'static str>,
}
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default, bon::Builder)]
#[serde(default)]
pub struct PingEvent {
  #[doc(hidden)]
  #[serde(default, rename = "type", skip_deserializing)]
  #[default(Some("ping"))]
  #[builder(skip = Some("ping"))]
  pub r#type: Option<&'static str>,
}
/// Delta content for streaming
#[derive(Debug, Clone, PartialEq)]
pub enum Delta {
  Text(TextDelta),
  InputJson(InputJsonDelta),
}
impl Delta {
  pub const DISCRIMINATOR_FIELD: &'static str = "type";
}
impl Default for Delta {
  fn default() -> Self {
    Self::Text(<TextDelta>::default())
  }
}
impl<'de> serde::Deserialize<'de> for Delta {
  fn deserialize<D>(deserializer: D) -> core::result::Result<Self, D::Error>
  where
    D: serde::Deserializer<'de>,
  {
    let value = serde_json::Value::deserialize(deserializer)?;
    match value.get(Self::DISCRIMINATOR_FIELD).and_then(|v| v.as_str()) {
      Some("text_delta") => serde_json::from_value(value)
        .map(Self::Text)
        .map_err(serde::de::Error::custom),
      Some("input_json_delta") => serde_json::from_value(value)
        .map(Self::InputJson)
        .map_err(serde::de::Error::custom),
      None => Err(serde::de::Error::missing_field(Self::DISCRIMINATOR_FIELD)),
      Some(other) => Err(serde::de::Error::custom(format!(
        "Unknown discriminator value '{}' for field '{}'",
        other, "type"
      ))),
    }
  }
}
impl Delta {
  pub fn text(text: String) -> Self {
    Self::Text(TextDelta {
      text,
      ..Default::default()
    })
  }
  pub fn input_json(partial_json: String) -> Self {
    Self::InputJson(InputJsonDelta {
      partial_json,
      ..Default::default()
    })
  }
}
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default, bon::Builder)]
#[serde(default)]
pub struct TextDelta {
  #[doc(hidden)]
  #[serde(default, rename = "type", skip_deserializing)]
  #[default(Some("text_delta"))]
  #[builder(skip = Some("text_delta"))]
  pub r#type: Option<&'static str>,
  pub text: String,
}
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default, bon::Builder)]
#[serde(default)]
pub struct InputJsonDelta {
  #[doc(hidden)]
  #[serde(default, rename = "type", skip_deserializing)]
  #[default(Some("input_json_delta"))]
  #[builder(skip = Some("input_json_delta"))]
  pub r#type: Option<&'static str>,
  pub partial_json: String,
}
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default, bon::Builder)]
pub struct Message {
  pub id: String,
  pub role: Role,
  pub content: Vec<ContentBlock>,
  pub model: String,
  pub stop_reason: Option<StopReason>,
  pub usage: Option<Usage>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, oas3_gen_support::Default)]
pub enum Role {
  #[serde(rename = "user")]
  #[default]
  User,
  #[serde(rename = "assistant")]
  Assistant,
}
impl core::fmt::Display for Role {
  fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    match self {
      Self::User => write!(f, "user"),
      Self::Assistant => write!(f, "assistant"),
    }
  }
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, oas3_gen_support::Default)]
pub enum StopReason {
  #[serde(rename = "end_turn")]
  #[default]
  EndTurn,
  #[serde(rename = "max_tokens")]
  MaxTokens,
  #[serde(rename = "stop_sequence")]
  StopSequence,
  #[serde(rename = "tool_use")]
  ToolUse,
}
impl core::fmt::Display for StopReason {
  fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    match self {
      Self::EndTurn => write!(f, "end_turn"),
      Self::MaxTokens => write!(f, "max_tokens"),
      Self::StopSequence => write!(f, "stop_sequence"),
      Self::ToolUse => write!(f, "tool_use"),
    }
  }
}
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default, bon::Builder)]
pub struct Usage {
  pub input_tokens: i64,
  pub output_tokens: i64,
}
/// Flexible metadata that can be string or object
#[derive(Debug, Clone, PartialEq, Serialize, oas3_gen_support::Default)]
#[serde(untagged)]
pub enum Metadata {
  #[default]
  String(String),
  Object(indexmap::IndexMap<String, serde_json::Value>),
}
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default, bon::Builder)]
#[serde(default)]
pub struct ErrorResponse {
  #[serde(rename = "type")]
  #[default("error".to_string())]
  #[builder(default = "error".to_string())]
  pub r#type: String,
  pub error: ErrorDetails,
}
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default, bon::Builder)]
pub struct ErrorDetails {
  #[serde(rename = "type")]
  pub r#type: ErrorType,
  pub message: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, oas3_gen_support::Default)]
pub enum ErrorType {
  #[serde(rename = "invalid_request_error")]
  #[default]
  InvalidRequestError,
  #[serde(rename = "authentication_error")]
  AuthenticationError,
  #[serde(rename = "permission_error")]
  PermissionError,
  #[serde(rename = "not_found_error")]
  NotFoundError,
  #[serde(rename = "rate_limit_error")]
  RateLimitError,
  #[serde(rename = "api_error")]
  ApiError,
  #[serde(rename = "overloaded_error")]
  OverloadedError,
}
impl core::fmt::Display for ErrorType {
  fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    match self {
      Self::InvalidRequestError => write!(f, "invalid_request_error"),
      Self::AuthenticationError => write!(f, "authentication_error"),
      Self::PermissionError => write!(f, "permission_error"),
      Self::NotFoundError => write!(f, "not_found_error"),
      Self::RateLimitError => write!(f, "rate_limit_error"),
      Self::ApiError => write!(f, "api_error"),
      Self::OverloadedError => write!(f, "overloaded_error"),
    }
  }
}
/// Test nullable union with primitives
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, oas3_gen_support::Default)]
#[serde(untagged)]
pub enum NullableStringOrNumber {
  #[default]
  String(String),
  Number(f64),
}
/// Test union that can be single item or array
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, oas3_gen_support::Default)]
#[serde(untagged)]
pub enum ArrayOrSingle {
  #[default]
  TextBlock(TextBlock),
  Array(Vec<TextBlock>),
}
impl ArrayOrSingle {
  pub fn text_block(text: String) -> Self {
    Self::TextBlock(TextBlock {
      text,
      ..Default::default()
    })
  }
}
#[serde_with::skip_serializing_none]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, oas3_gen_support::Default, bon::Builder)]
#[serde(default)]
pub struct RecipeList {
  pub ingredients: Option<indexmap::IndexMap<String, serde_json::Value>>,
  pub required: Option<Vec<String>>,
  #[serde(rename = "type")]
  #[default("object".to_string())]
  #[builder(default = "object".to_string())]
  pub r#type: String,
  /// Additional properties not defined in the schema.
  #[serde(flatten)]
  pub additional_properties: indexmap::IndexMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, oas3_gen_support::Default)]
#[serde(untagged)]
pub enum UsageCounters {
  #[default]
  A(UsageCounterA),
  B(UsageCounterB),
}
impl UsageCounters {
  pub fn a(output_tokens: i64) -> Self {
    Self::A(UsageCounterA {
      output_tokens,
      ..Default::default()
    })
  }
  pub fn b(output_tokens: i64) -> Self {
    Self::B(UsageCounterB {
      output_tokens,
      ..Default::default()
    })
  }
}
/// Hypothetical nested nullable union for flattening coverage
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, oas3_gen_support::Default)]
#[serde(untagged)]
pub enum HypotheticalVersion {
  #[default]
  Citation(CitationAnnotation),
  Link(LinkAnnotation),
}
#[serde_with::skip_serializing_none]
#[derive(
  Debug, Clone, PartialEq, Serialize, Deserialize, validator::Validate, oas3_gen_support::Default, bon::Builder,
)]
#[serde(default)]
pub struct UsageCounterA {
  #[validate(range(min = 0i64))]
  pub output_tokens: i64,
  #[serde(rename = "type")]
  #[default(Some("counter_a".to_string()))]
  pub r#type: Option<String>,
}
#[serde_with::skip_serializing_none]
#[derive(
  Debug, Clone, PartialEq, Serialize, Deserialize, validator::Validate, oas3_gen_support::Default, bon::Builder,
)]
#[serde(default)]
pub struct UsageCounterB {
  #[validate(range(min = 0i64))]
  pub output_tokens: i64,
  #[serde(rename = "type")]
  #[default(Some("counter_b".to_string()))]
  pub r#type: Option<String>,
}
/// Send content blocks
#[derive(Debug, Clone, validator::Validate, oas3_gen_support::Default)]
pub struct SendContentRequest {
  pub body: ContentRequest,
}
#[bon::bon]
impl SendContentRequest {
  /// Create a new request with the given parameters.
  #[builder]
  pub fn new(body: ContentRequest) -> anyhow::Result<Self> {
    let request = Self { body };
    request.validate()?;
    Ok(request)
  }
}
impl SendContentRequest {
  /// Parse the HTTP response into the response enum.
  pub async fn parse_response(req: reqwest::Response) -> anyhow::Result<SendContentResponse> {
    let status = req.status();
    if status == http::StatusCode::OK {
      let data = oas3_gen_support::Diagnostics::<ContentResponse>::json_with_diagnostics(req).await?;
      return Ok(SendContentResponse::Ok(data));
    }
    if status == http::StatusCode::BAD_REQUEST {
      let data = oas3_gen_support::Diagnostics::<ErrorResponse>::json_with_diagnostics(req).await?;
      return Ok(SendContentResponse::BadRequest(data));
    }
    let _ = req.bytes().await?;
    Ok(SendContentResponse::Unknown)
  }
}
/// Response types for sendContent
#[derive(Debug, Clone)]
pub enum SendContentResponse {
  ///200: Success
  Ok(ContentResponse),
  ///400: Bad request
  BadRequest(ErrorResponse),
  ///default: Unknown response
  Unknown,
}
/// Get events with discriminated union
#[derive(Debug, Clone, validator::Validate, oas3_gen_support::Default)]
pub struct GetEventsRequest {}
impl GetEventsRequest {
  /// Parse the HTTP response into the response enum.
  pub async fn parse_response(req: reqwest::Response) -> anyhow::Result<GetEventsResponse> {
    let status = req.status();
    if status == http::StatusCode::OK {
      let data = oas3_gen_support::Diagnostics::<EventList>::json_with_diagnostics(req).await?;
      return Ok(GetEventsResponse::Ok(data));
    }
    let _ = req.bytes().await?;
    Ok(GetEventsResponse::Unknown)
  }
}
/// Response types for getEvents
#[derive(Debug, Clone)]
pub enum GetEventsResponse {
  ///200: Event stream
  Ok(EventList),
  ///default: Unknown response
  Unknown,
}
