use serde::{Deserialize, Serialize};
use super::button::RichMessageButton;
use super::common::User;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RichText {
Plain(String),
Concat(Vec<RichText>),
Entity(Box<RichTextEntity>),
}
impl RichText {
pub fn plain(s: impl Into<String>) -> Self {
RichText::Plain(s.into())
}
pub fn entity(e: RichTextEntity) -> Self {
RichText::Entity(Box::new(e))
}
}
impl From<&str> for RichText {
fn from(s: &str) -> Self {
RichText::Plain(s.to_owned())
}
}
impl From<String> for RichText {
fn from(s: String) -> Self {
RichText::Plain(s)
}
}
impl From<Vec<RichText>> for RichText {
fn from(v: Vec<RichText>) -> Self {
RichText::Concat(v)
}
}
impl From<RichTextEntity> for RichText {
fn from(e: RichTextEntity) -> Self {
RichText::entity(e)
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum RichTextEntity {
Bold {
text: RichText,
},
Italic {
text: RichText,
},
Underline {
text: RichText,
},
Strikethrough {
text: RichText,
},
Spoiler {
text: RichText,
},
DateTime {
text: RichText,
unix_time: i64,
date_time_format: String,
},
TextMention {
text: RichText,
user: User,
},
Subscript {
text: RichText,
},
Superscript {
text: RichText,
},
Marked {
text: RichText,
},
Code {
text: RichText,
},
CustomEmoji {
custom_emoji_id: String,
alternative_text: String,
},
MathematicalExpression {
expression: String,
},
Url {
text: RichText,
url: String,
},
EmailAddress {
text: RichText,
email_address: String,
},
PhoneNumber {
text: RichText,
phone_number: String,
},
BankCardNumber {
text: RichText,
bank_card_number: String,
},
TonAddress {
text: RichText,
address: String,
},
Mention {
text: RichText,
username: String,
},
Hashtag {
text: RichText,
hashtag: String,
},
Cashtag {
text: RichText,
cashtag: String,
},
BotCommand {
text: RichText,
bot_command: String,
},
Button {
button: RichMessageButton,
},
Anchor {
name: String,
},
AnchorLink {
text: RichText,
anchor_name: String,
},
Reference {
text: RichText,
name: String,
},
ReferenceLink {
text: RichText,
reference_name: String,
},
}