use schemars::JsonSchema;
use serde::Deserialize;
use void_crawl_core::{SelectorEntry, SelectorKind};
#[derive(Debug, Clone, Copy, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum SelectorKindArg {
Css,
Xpath,
Regex,
Jsonld,
Attr,
GlobalId,
Role,
Visual,
}
impl From<SelectorKindArg> for SelectorKind {
fn from(kind: SelectorKindArg) -> Self {
match kind {
SelectorKindArg::Css => Self::Css,
SelectorKindArg::Xpath => Self::Xpath,
SelectorKindArg::Regex => Self::Regex,
SelectorKindArg::Jsonld => Self::Jsonld,
SelectorKindArg::Attr => Self::Attr,
SelectorKindArg::GlobalId => Self::GlobalId,
SelectorKindArg::Role => Self::Role,
SelectorKindArg::Visual => Self::Visual,
}
}
}
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct SelectorArg {
#[serde(rename = "type")]
pub kind: SelectorKindArg,
#[serde(default)]
pub value: Option<String>,
#[serde(default)]
pub regex: Option<String>,
#[serde(default)]
pub name: Option<String>,
#[serde(default)]
pub nth: Option<u32>,
#[serde(default)]
pub x: Option<f64>,
#[serde(default)]
pub y: Option<f64>,
}
impl From<SelectorArg> for SelectorEntry {
fn from(arg: SelectorArg) -> Self {
Self {
kind: arg.kind.into(),
value: arg.value.unwrap_or_default(),
regex: arg.regex,
name: arg.name,
nth: arg.nth,
x: arg.x,
y: arg.y,
}
}
}