use crate::keyboard::Keyboard;
use std::fmt::{Display, Error, Formatter};
#[derive(Debug)]
pub struct Response {
message: String,
attachments: Vec<AttachmentInformation>,
keyboard: Option<Keyboard>,
}
impl Default for Response {
fn default() -> Self {
Self {
message: String::new(),
attachments: Vec::new(),
keyboard: None,
}
}
}
impl Response {
pub fn new() -> Self {
Default::default()
}
pub fn attachments(&self) -> &Vec<AttachmentInformation> {
&self.attachments
}
pub fn attach(&mut self, info: AttachmentInformation) {
self.attachments.push(info);
}
pub fn message(&self) -> &String {
&self.message
}
pub fn set_message(&mut self, msg: &str) {
self.message = msg.into();
}
pub fn keyboard(&self) -> &Option<Keyboard> {
&self.keyboard
}
pub fn set_keyboard(&mut self, kbd: Keyboard) {
self.keyboard = Some(kbd);
}
pub fn set_keyboard_empty(&mut self) {
self.keyboard = Some(Default::default());
}
}
#[derive(Debug)]
pub struct AttachmentInformation {
r#type: String,
owner_id: i64,
resource_id: i64,
access_key: Option<String>,
}
impl Display for AttachmentInformation {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
f.write_str(&format!(
"{}{}_{}{}",
self.r#type,
self.owner_id,
self.resource_id,
match &self.access_key {
Some(key) => format!("_{}", key),
None => "".into(),
}
))
}
}
impl From<(String, i64, i64)> for AttachmentInformation {
fn from((r#type, owner_id, resource_id): (String, i64, i64)) -> Self {
Self {
r#type,
owner_id,
resource_id,
access_key: None,
}
}
}
impl From<(String, i64, i64, String)> for AttachmentInformation {
fn from((r#type, owner_id, resource_id, access_key): (String, i64, i64, String)) -> Self {
Self {
r#type,
owner_id,
resource_id,
access_key: Some(access_key),
}
}
}
impl AttachmentInformation {
pub fn new(
r#type: String,
owner_id: i64,
resource_id: i64,
access_key: Option<String>,
) -> Self {
Self {
r#type,
owner_id,
resource_id,
access_key,
}
}
}