use crate::{
	user::UserId,
	util::{macros::string_id_type, serde::wrappers::SerializableDateTime},
};
use language_tags::LanguageTag;
use serde::Deserialize;
use time::OffsetDateTime;

string_id_type!(SpaceId);

#[derive(FlatDebug, Debug, Clone, PartialEq, Eq, Deserialize)]
pub struct Space {
	id: SpaceId,
	state: String,
}

impl Space {
	/// The unique identifier of the requested Space.
	#[inline]
	pub fn id(&self) -> &SpaceId {
		&self.id
	}

	/// Indicates if the Space has started or will start in the future, or if it has ended.
	#[inline]
	pub fn state(&self) -> &str {
		&self.state
	}
}

#[getter]
pub struct SpaceCreatedAt {
	/// Creation time of this Space.
	#[as_deref(OffsetDateTime)]
	created_at: SerializableDateTime,
}

#[getter]
pub struct SpaceEndedAt {
	/// Time when the Space was ended. Only available for ended Spaces.
	#[as_deref(OffsetDateTime)]
	ended_at: SerializableDateTime,
}

#[getter]
pub struct SpaceHostIds {
	/// The unique identifier of the users who are hosting this Space.
	#[as_ref([UserId])]
	host_ids: Vec<UserId>,
}

#[getter]
pub struct SpaceLang {
	/// Language of the Space, if detected by Twitter.
	/// Returned as a BCP47 language tag.
	#[as_ref]
	lang: LanguageTag,
}

#[getter]
pub struct SpaceIsTicketed {
	/// Indicates is this is a ticketed Space.
	is_ticketed: bool,
}

#[getter]
pub struct SpaceInvitedUserIds {
	/// The list of user IDs that were invited to join as speakers.
	/// Usually, users in this list are invited to speak via the Invite user option.
	#[as_ref([UserId])]
	invited_user_ids: Vec<UserId>,
}

#[getter]
pub struct SpaceParticipantCount {
	/// The current number of users in the Space, including Hosts and Speakers.
	participant_count: u64,
}

#[getter]
pub struct SpaceScheduledStart {
	/// Indicates the start time of a scheduled Space, as set by the creator of the Space.
	/// This field is returned only if the Space has been scheduled;
	/// in other words, if the field is returned, it means the Space is a scheduled Space.
	#[as_deref(OffsetDateTime)]
	scheduled_start: SerializableDateTime,
}

#[getter]
pub struct SpaceSpeakerIds {
	/// The list of users who were speaking at any point during the Space.
	/// This list contains all the users in `invited_user_ids` in addition to any user who requested to speak and was allowed via the Add speaker option.
	#[as_ref([UserId])]
	speaker_ids: Vec<UserId>,
}

#[getter]
pub struct SpaceStartedAt {
	/// Indicates the actual start time of a Space.
	#[as_deref(OffsetDateTime)]
	started_at: SerializableDateTime,
}

#[getter]
pub struct SpaceTitle {
	/// The title of the Space as specified by the creator.
	#[as_ref(str)]
	title: String,
}

#[getter]
pub struct SpaceUpdatedAt {
	/// Specifies the date and time of the last update to any of the Space's metadata, such as its title or scheduled time.
	#[as_deref(OffsetDateTime)]
	updated_at: SerializableDateTime,
}
