#[cfg(feature = "validator")]
use validator::Validate;
use super::File;
auto_derived_partial!(
pub struct Webhook {
pub id: String,
pub name: String,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub avatar: Option<File>,
pub channel_id: String,
pub permissions: u64,
pub token: Option<String>,
},
"PartialWebhook"
);
auto_derived!(
pub struct MessageWebhook {
pub name: String,
pub avatar: Option<String>,
}
#[cfg_attr(feature = "validator", derive(validator::Validate))]
pub struct DataEditWebhook {
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
pub name: Option<String>,
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 128)))]
pub avatar: Option<String>,
pub permissions: Option<u64>,
#[cfg_attr(feature = "serde", serde(default))]
pub remove: Vec<FieldsWebhook>,
}
pub struct ResponseWebhook {
pub id: String,
pub name: String,
pub avatar: Option<String>,
pub channel_id: String,
pub permissions: u64,
}
pub enum FieldsWebhook {
Avatar,
}
#[cfg_attr(feature = "validator", derive(Validate))]
pub struct CreateWebhookBody {
#[validate(length(min = 1, max = 32))]
pub name: String,
#[validate(length(min = 1, max = 128))]
pub avatar: Option<String>,
}
);
impl From<Webhook> for MessageWebhook {
fn from(value: Webhook) -> Self {
MessageWebhook {
name: value.name,
avatar: value.avatar.map(|file| file.id),
}
}
}
impl From<Webhook> for ResponseWebhook {
fn from(value: Webhook) -> Self {
ResponseWebhook {
id: value.id,
name: value.name,
avatar: value.avatar.map(|file| file.id),
channel_id: value.channel_id,
permissions: value.permissions,
}
}
}