#![allow(clippy::all, missing_docs, unused_imports)]
use serde::{Deserialize, Serialize};
use super::*;
use crate::playwright::connection::{
Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
};
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ArtifactInitializer {
#[serde(rename = "absolutePath")]
pub absolute_path: String,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ArtifactPathAfterFinishedResult {
#[serde(rename = "value")]
pub value: String,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ArtifactSaveAsParams {
#[serde(rename = "path")]
pub path: String,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ArtifactSaveAsStreamResult {
#[serde(rename = "stream")]
pub stream: Ref<Stream>,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ArtifactFailureResult {
#[serde(rename = "error", default, skip_serializing_if = "Option::is_none")]
pub error: Option<String>,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ArtifactStreamResult {
#[serde(rename = "stream")]
pub stream: Ref<Stream>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ArtifactEvent {
Unknown {
method: String,
params: serde_json::Value,
},
}
impl ProtocolEvent for ArtifactEvent {
fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
match method {
_ => Ok(Self::Unknown { method: method.to_string(), params }),
}
}
}
#[derive(Debug, Clone)]
pub struct Artifact {
channel: Channel,
}
impl ChannelType for Artifact {
const INTERFACE: &'static str = "Artifact";
type Initializer = ArtifactInitializer;
type Event = ArtifactEvent;
fn accepts(interface: &str) -> bool {
matches!(interface, "Artifact")
}
fn from_channel(channel: Channel) -> Self {
Self { channel }
}
fn channel(&self) -> &Channel {
&self.channel
}
}
impl Artifact {
pub async fn path_after_finished(&self) -> Result<ArtifactPathAfterFinishedResult, ProtocolError> {
self.channel.send("pathAfterFinished", &serde_json::json!({})).await
}
pub async fn save_as(&self, params: ArtifactSaveAsParams) -> Result<(), ProtocolError> {
self.channel.send_no_result("saveAs", ¶ms).await
}
pub async fn save_as_stream(&self) -> Result<ArtifactSaveAsStreamResult, ProtocolError> {
self.channel.send("saveAsStream", &serde_json::json!({})).await
}
pub async fn failure(&self) -> Result<ArtifactFailureResult, ProtocolError> {
self.channel.send("failure", &serde_json::json!({})).await
}
pub async fn stream(&self) -> Result<ArtifactStreamResult, ProtocolError> {
self.channel.send("stream", &serde_json::json!({})).await
}
pub async fn cancel(&self) -> Result<(), ProtocolError> {
self.channel.send_no_result("cancel", &serde_json::json!({})).await
}
pub async fn delete(&self) -> Result<(), ProtocolError> {
self.channel.send_no_result("delete", &serde_json::json!({})).await
}
}