use crate::Identity;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
pub struct GroupId(pub String);
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Group {
pub id: GroupId,
pub name: String,
pub participants: Vec<Identity>,
pub threshold_key: Option<Vec<u8>>,
pub settings: GroupSettings,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GroupSettings {
pub max_participants: usize,
pub message_retention_days: u32,
pub max_file_size_mb: u32,
}
impl Default for GroupSettings {
fn default() -> Self {
Self {
max_participants: 20,
message_retention_days: 7,
max_file_size_mb: 5,
}
}
}
impl Group {
pub fn new(name: String) -> Self {
Self {
id: GroupId(format!("group-{}", chrono::Utc::now().timestamp())),
name,
participants: Vec::new(),
threshold_key: None,
settings: GroupSettings::default(),
}
}
pub fn add_participant(&mut self, identity: Identity) -> Result<(), super::ChatError> {
if self.participants.len() >= self.settings.max_participants {
return Err(super::ChatError::GroupSizeLimitExceeded);
}
if !self.participants.iter().any(|p| p.four_word_address == identity.four_word_address) {
self.participants.push(identity);
}
Ok(())
}
}