#![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 DialogInitializer {
#[serde(rename = "page", default, skip_serializing_if = "Option::is_none")]
pub page: Option<Ref<Page>>,
#[serde(rename = "type")]
pub r#type: String,
#[serde(rename = "message")]
pub message: String,
#[serde(rename = "defaultValue")]
pub default_value: String,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DialogAcceptParams {
#[serde(rename = "promptText", default, skip_serializing_if = "Option::is_none")]
pub prompt_text: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum DialogEvent {
Unknown {
method: String,
params: serde_json::Value,
},
}
impl ProtocolEvent for DialogEvent {
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 Dialog {
channel: Channel,
}
impl ChannelType for Dialog {
const INTERFACE: &'static str = "Dialog";
type Initializer = DialogInitializer;
type Event = DialogEvent;
fn accepts(interface: &str) -> bool {
matches!(interface, "Dialog")
}
fn from_channel(channel: Channel) -> Self {
Self { channel }
}
fn channel(&self) -> &Channel {
&self.channel
}
}
impl Dialog {
pub async fn accept(&self, params: DialogAcceptParams) -> Result<(), ProtocolError> {
self.channel.send_no_result("accept", ¶ms).await
}
pub async fn dismiss(&self) -> Result<(), ProtocolError> {
self.channel.send_no_result("dismiss", &serde_json::json!({})).await
}
}