use serde::{Deserialize, Serialize};
use crate::models::payloads::APIEntitlement;
use super::{
channel::APIWebhookSourceChannel,
guild::{APIGuild, APIWebhookSourceGuild},
interactions::ApplicationIntegrationType,
oauth2::OAuth2Scopes,
user::APIUser,
};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct APIWebhook {
pub id: String,
pub r#type: WebhookType,
pub guild_id: Option<String>,
pub channel_id: String,
pub user: Option<APIUser>,
pub name: Option<String>,
pub avatar: Option<String>,
pub token: Option<String>,
pub application_id: Option<String>,
pub source_guild: Option<APIWebhookSourceGuild>,
pub source_channel: Option<APIWebhookSourceChannel>,
pub url: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum APIWebhookEvent {
Event(APIWebhookEventBase<ApplicationWebhookType, APIWebhookEventBody>),
Ping(APIWebhookEventBase<ApplicationWebhookType, ()>),
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum APIWebhookEventBody {
#[serde(rename = "APPLICATION_AUTHORIZED")]
ApplicationAuthorized {
timestamp: String,
data: APIWebhookEventApplicationAuthorizedData,
},
#[serde(rename = "APPLICATION_DEAUTHORIZED")]
ApplicationDeauthorized {
timestamp: String,
data: APIWebhookEventApplicationDeauthorizedData,
},
#[serde(rename = "ENTITLEMENT_CREATE")]
EntitlementCreate {
timestamp: String,
data: APIWebhookEventEntitlementCreateData,
},
#[serde(rename = "QUEST_USER_ENROLLMENT")]
QuestUserEnrollment {
timestamp: String,
data: APIWebhookEventQuestUserEnrollmentData,
},
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct APIWebhookEventApplicationAuthorizedData {
pub integration_type: Option<ApplicationIntegrationType>,
pub user: APIUser,
pub scopes: Vec<OAuth2Scopes>,
pub guild: Option<APIGuild>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct APIWebhookEventApplicationDeauthorizedData {
pub user: APIUser,
}
pub type APIWebhookEventEntitlementCreateData = APIEntitlement;
pub type APIWebhookEventQuestUserEnrollmentData = ();
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ApplicationWebhookType {
Ping,
Event,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct APIWebhookEventBase<Type, Event> {
pub version: u8,
pub application_id: String,
pub r#type: Type,
pub event: Event,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct APIWebhookEventEventBase<Type, Data> {
pub r#type: Type,
pub timestamp: String,
pub data: Data,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ApplicationWebhookEventType {
#[serde(rename = "APPLICATION_AUTHORIZED")]
ApplicationAuthorized,
#[serde(rename = "APPLICATION_DEAUTHORIZED")]
ApplicationDeauthorized,
#[serde(rename = "ENTITLEMENT_CREATE")]
EntitlementCreate,
#[serde(rename = "QUEST_USER_ENROLLMENT")]
QuestUserEnrollment,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum WebhookType {
Incoming = 1,
ChannelFollower = 2,
Application = 3,
}