// this file is @generated
use clap::{Args, Subcommand};
use svix::api::Svix;
#[allow(unused_imports)]
use svix::models::*;

use super::{
    streaming_event_type::StreamingEventTypeArgs, streaming_events::StreamingEventsArgs,
    streaming_sink::StreamingSinkArgs, streaming_stream::StreamingStreamArgs,
};

#[derive(Args)]
#[command(args_conflicts_with_subcommands = true, flatten_help = true)]
pub struct StreamingArgs {
    #[command(subcommand)]
    pub command: StreamingCommands,
}

#[allow(clippy::large_enum_variant)]
#[derive(Subcommand)]
pub enum StreamingCommands {
    EventType(StreamingEventTypeArgs),
    Events(StreamingEventsArgs),
    Sink(StreamingSinkArgs),
    Stream(StreamingStreamArgs),
    /// Get the HTTP sink headers.
    ///
    /// Only valid for `http` or `otelTracing` sinks.
    #[command(help_template = concat!(
            "{about-with-newline}\n",
            "{usage-heading} {usage}\n\n",
            "Example: svix streaming sink-headers-get strm_abc000000000000000000 sink_abc000000000000000000\n",
            "{after-help}",
            "\n",
            "{all-args}",
        ))]
    #[command(after_help = "Example response:
{
  \"headers\": {
    \"X-Example\": \"123\",
    \"X-Foobar\": \"Bar\"
  },
  \"sensitive\": [\"Authorization\"]
}\n")]
    SinkHeadersGet {
        stream_id: String,
        sink_id: String,
    },
    /// Updates the Sink's headers.
    ///
    /// Only valid for `http` or `otelTracing` sinks.
    #[command(help_template = concat!(
            "{about-with-newline}\n",
            "{usage-heading} {usage}\n\n",
            "Example: svix streaming sink-headers-patch strm_abc000000000000000000 sink_abc000000000000000000 {...}\n",
            "{after-help}",
            "\n",
            "{all-args}",
        ))]
    #[command(after_help = "Example body:
{
  \"headers\": {
    \"X-Example\": \"123\",
    \"X-Foobar\": \"Bar\"
  }
}\n\nExample response:
{
  \"headers\": {
    \"X-Example\": \"123\",
    \"X-Foobar\": \"Bar\"
  },
  \"sensitive\": [\"Authorization\"]
}\n")]
    SinkHeadersPatch {
        stream_id: String,
        sink_id: String,
        http_sink_headers_patch_in: crate::json::JsonOf<HttpSinkHeadersPatchIn>,
    },
}

impl StreamingCommands {
    pub async fn exec(
        self,
        client: &Svix,
        color_mode: colored_json::ColorMode,
    ) -> anyhow::Result<()> {
        match self {
            Self::EventType(args) => {
                args.command.exec(client, color_mode).await?;
            }
            Self::Events(args) => {
                args.command.exec(client, color_mode).await?;
            }
            Self::Sink(args) => {
                args.command.exec(client, color_mode).await?;
            }
            Self::Stream(args) => {
                args.command.exec(client, color_mode).await?;
            }
            Self::SinkHeadersGet { stream_id, sink_id } => {
                let resp = client
                    .streaming()
                    .sink_headers_get(stream_id, sink_id)
                    .await?;
                crate::json::print_json_output(&resp, color_mode)?;
            }
            Self::SinkHeadersPatch {
                stream_id,
                sink_id,
                http_sink_headers_patch_in,
            } => {
                let resp = client
                    .streaming()
                    .sink_headers_patch(stream_id, sink_id, http_sink_headers_patch_in.into_inner())
                    .await?;
                crate::json::print_json_output(&resp, color_mode)?;
            }
        }

        Ok(())
    }
}
