use std::fmt::Display;
use serde::Serialize;
use crate::Color;
#[derive(Clone, Debug, Serialize)]
pub struct Embed {
pub title: String,
pub description: String,
pub color: u32,
pub fields: Vec<Field>,
}
impl Embed {
pub fn builder() -> EmbedBuilder {
EmbedBuilder
}
}
#[derive(Clone, Debug, Serialize)]
pub struct Field {
pub name: String,
pub value: String,
}
pub struct EmbedBuilder;
impl EmbedBuilder {
pub fn title<T: Display>(self, title: T) -> EmbedBuilderWithTitle {
EmbedBuilderWithTitle {
title: title.to_string(),
}
}
}
pub struct EmbedBuilderWithTitle {
title: String,
}
impl EmbedBuilderWithTitle {
pub fn description<T: Display>(self, description: T) -> EmbedBuilderWithDescription {
EmbedBuilderWithDescription {
title: self.title,
description: description.to_string(),
}
}
}
pub struct EmbedBuilderWithDescription {
title: String,
description: String,
}
impl EmbedBuilderWithDescription {
pub fn color(self, color: Color) -> EmbedBuilderWithColor {
EmbedBuilderWithColor {
title: self.title,
description: self.description,
color: color.to_u32(),
fields: Vec::new(),
}
}
}
pub struct EmbedBuilderWithColor {
title: String,
description: String,
color: u32,
fields: Vec<Field>,
}
impl EmbedBuilderWithColor {
pub fn build(self) -> Embed {
Embed {
title: self.title,
description: self.description,
color: self.color,
fields: self.fields,
}
}
pub fn field<T: Display, U: Display>(mut self, name: T, value: U) -> Self {
self.fields.push(Field {
name: name.to_string(),
value: value.to_string(),
});
self
}
}