use crate::parsoid::{ImmutableWikicode, Wikicode};
use mwapi_responses::timestamp::Timestamp;
use serde::Deserialize;
pub struct SaveOptions {
pub(crate) summary: String,
pub(crate) mark_as_bot: Option<bool>,
pub(crate) tags: Vec<String>,
}
impl SaveOptions {
pub fn summary(summary: &str) -> Self {
Self {
summary: summary.to_string(),
mark_as_bot: None,
tags: vec![],
}
}
pub fn set_summary(mut self, summary: &str) -> Self {
self.summary = summary.to_string();
self
}
pub fn mark_as_bot(mut self, mark: bool) -> Self {
self.mark_as_bot = Some(mark);
self
}
pub fn add_tag(mut self, tag: &str) -> Self {
self.tags.push(tag.to_string());
self
}
}
pub enum Saveable {
Wikitext(String),
Html(ImmutableWikicode),
}
impl From<String> for Saveable {
fn from(wikitext: String) -> Self {
Self::Wikitext(wikitext)
}
}
impl From<&str> for Saveable {
fn from(wikitext: &str) -> Self {
Self::Wikitext(wikitext.to_string())
}
}
impl From<&String> for Saveable {
fn from(wikitext: &String) -> Self {
Self::Wikitext(wikitext.to_string())
}
}
impl From<Wikicode> for Saveable {
fn from(html: Wikicode) -> Self {
html.into_immutable().into()
}
}
impl From<ImmutableWikicode> for Saveable {
fn from(html: ImmutableWikicode) -> Self {
Self::Html(html)
}
}
#[derive(Deserialize, Clone, Debug)]
pub struct EditResponse {
pub contentmodel: String,
pub newrevid: Option<u64>,
pub newtimestamp: Option<Timestamp>,
pub oldrevid: Option<u64>,
#[serde(default)]
pub nochange: bool,
#[serde(default)]
pub new: bool,
pub pageid: u32,
pub result: String,
pub title: String,
}