use super::UpdateChannelPermissionConfigured;
use crate::client::Client;
use twilight_model::{
channel::permission_overwrite::PermissionOverwriteType,
guild::Permissions,
id::{ChannelId, RoleId, UserId},
};
pub struct UpdateChannelPermission<'a> {
allow: Permissions,
channel_id: ChannelId,
deny: Permissions,
http: &'a Client,
}
impl<'a> UpdateChannelPermission<'a> {
pub(crate) const fn new(
http: &'a Client,
channel_id: ChannelId,
allow: Permissions,
deny: Permissions,
) -> Self {
Self {
allow,
channel_id,
deny,
http,
}
}
pub fn member(self, user_id: impl Into<UserId>) -> UpdateChannelPermissionConfigured<'a> {
self.configure(&PermissionOverwriteType::Member(user_id.into()))
}
pub fn role(self, role_id: impl Into<RoleId>) -> UpdateChannelPermissionConfigured<'a> {
self.configure(&PermissionOverwriteType::Role(role_id.into()))
}
fn configure(self, target: &PermissionOverwriteType) -> UpdateChannelPermissionConfigured<'a> {
UpdateChannelPermissionConfigured::new(
self.http,
self.channel_id,
self.allow,
self.deny,
target,
)
}
}