//!
//! AUTO-GENERATED CODE - DO NOT EDIT!
//!
//! Event Stream API
//! Source: crates/oas3-gen/fixtures/event_stream.json
//! Version: 1.0.0
//! Generated by `oas3-gen v0.26.0`
//!
//! API with Server-Sent Events (SSE) endpoint

use serde::{Deserialize, Serialize};
use validator::Validate;
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default, bon::Builder)]
pub struct StreamEvent {
  /// Unique event identifier
  pub id: String,
  /// Event data payload
  pub data: String,
  /// Event timestamp
  pub timestamp: Option<chrono::DateTime<chrono::Utc>>,
}
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default, bon::Builder)]
pub struct TypedEvent {
  /// Event type
  #[serde(rename = "type")]
  pub r#type: TypedEventType,
  pub payload: EventPayload,
}
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default, bon::Builder)]
pub struct EventPayload {
  pub id: String,
  pub name: Option<String>,
  pub value: Option<i64>,
}
/// Returns a stream of server-sent events
#[derive(Debug, Clone, validator::Validate, oas3_gen_support::Default)]
pub struct EventsRequest {}
impl EventsRequest {
  /// Parse the HTTP response into the response enum.
  pub async fn parse_response(req: reqwest::Response) -> anyhow::Result<EventsResponse> {
    let status = req.status();
    if status == http::StatusCode::OK {
      let data = <oas3_gen_support::EventStream<StreamEvent>>::from_response(req);
      return Ok(EventsResponse::Ok(data));
    }
    let _ = req.bytes().await?;
    Ok(EventsResponse::Unknown)
  }
}
/// Response types for streamEvents
#[derive(Debug)]
pub enum EventsResponse {
  ///200: A stream of events
  Ok(oas3_gen_support::EventStream<StreamEvent>),
  ///default: Unknown response
  Unknown,
}
#[serde_with::skip_serializing_none]
#[derive(Debug, Clone, PartialEq, Serialize, oas3_gen_support::Default)]
pub struct TypedEventsRequestQuery {
  pub filter: Option<String>,
}
/// Returns a stream of typed server-sent events with query parameters
#[derive(Debug, Clone, validator::Validate, oas3_gen_support::Default)]
pub struct TypedEventsRequest {
  pub query: TypedEventsRequestQuery,
}
#[bon::bon]
impl TypedEventsRequest {
  /// Create a new request with the given parameters.
  #[builder]
  pub fn new(filter: Option<String>) -> anyhow::Result<Self> {
    let request = Self {
      query: TypedEventsRequestQuery { filter },
    };
    request.validate()?;
    Ok(request)
  }
}
impl TypedEventsRequest {
  /// Parse the HTTP response into the response enum.
  pub async fn parse_response(req: reqwest::Response) -> anyhow::Result<TypedEventsResponse> {
    let status = req.status();
    if status == http::StatusCode::OK {
      let data = <oas3_gen_support::EventStream<TypedEvent>>::from_response(req);
      return Ok(TypedEventsResponse::Ok(data));
    }
    let _ = req.bytes().await?;
    Ok(TypedEventsResponse::Unknown)
  }
}
/// Response types for streamTypedEvents
#[derive(Debug)]
pub enum TypedEventsResponse {
  ///200: A stream of typed events
  Ok(oas3_gen_support::EventStream<TypedEvent>),
  ///default: Unknown response
  Unknown,
}
/// Event type
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, oas3_gen_support::Default)]
pub enum TypedEventType {
  #[serde(rename = "created")]
  #[default]
  Created,
  #[serde(rename = "updated")]
  Updated,
  #[serde(rename = "deleted")]
  Deleted,
}
impl core::fmt::Display for TypedEventType {
  fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    match self {
      Self::Created => write!(f, "created"),
      Self::Updated => write!(f, "updated"),
      Self::Deleted => write!(f, "deleted"),
    }
  }
}
