use super::{CreateGuildScheduledEvent, CreateGuildScheduledEventFields};
use crate::{
error::Error,
request::{AuditLogReason, Request, TryIntoRequest},
response::{Response, ResponseFuture},
};
use std::future::IntoFuture;
use twilight_model::{
guild::scheduled_event::{EntityType, GuildScheduledEvent},
id::{marker::ChannelMarker, Id},
util::Timestamp,
};
use twilight_validate::request::{
audit_reason as validate_audit_reason,
scheduled_event_description as validate_scheduled_event_description, ValidationError,
};
#[must_use = "requests must be configured and executed"]
pub struct CreateGuildStageInstanceScheduledEvent<'a>(CreateGuildScheduledEvent<'a>);
impl<'a> CreateGuildStageInstanceScheduledEvent<'a> {
pub(crate) const fn new(
inner: CreateGuildScheduledEvent<'a>,
channel_id: Id<ChannelMarker>,
name: &'a str,
scheduled_start_time: &'a Timestamp,
) -> Self {
Self(CreateGuildScheduledEvent {
fields: CreateGuildScheduledEventFields {
channel_id: Some(channel_id),
entity_type: Some(EntityType::StageInstance),
name: Some(name),
scheduled_start_time: Some(scheduled_start_time),
..inner.fields
},
..inner
})
}
pub fn description(mut self, description: &'a str) -> Result<Self, ValidationError> {
validate_scheduled_event_description(description)?;
self.0.fields.description = Some(description);
Ok(self)
}
pub const fn image(mut self, image: &'a str) -> Self {
self.0.fields.image = Some(image);
self
}
pub const fn scheduled_end_time(mut self, scheduled_end_time: &'a Timestamp) -> Self {
self.0.fields.scheduled_end_time = Some(scheduled_end_time);
self
}
#[deprecated(since = "0.14.0", note = "use `.await` or `into_future` instead")]
pub fn exec(self) -> ResponseFuture<GuildScheduledEvent> {
self.into_future()
}
}
impl<'a> AuditLogReason<'a> for CreateGuildStageInstanceScheduledEvent<'a> {
fn reason(mut self, reason: &'a str) -> Result<Self, ValidationError> {
validate_audit_reason(reason)?;
self.0.reason.replace(reason);
Ok(self)
}
}
impl IntoFuture for CreateGuildStageInstanceScheduledEvent<'_> {
type Output = Result<Response<GuildScheduledEvent>, Error>;
type IntoFuture = ResponseFuture<GuildScheduledEvent>;
fn into_future(self) -> Self::IntoFuture {
self.0.exec()
}
}
impl TryIntoRequest for CreateGuildStageInstanceScheduledEvent<'_> {
fn try_into_request(self) -> Result<Request, Error> {
self.0.try_into_request()
}
}