use std::collections::HashSet;
use std::fmt::Debug;
use crate::Access;
use crate::group::GroupMember;
use crate::traits::{IdentityHandle, OperationId};
pub trait Groups<ID, OP, M, C>
where
ID: IdentityHandle,
OP: OperationId,
{
type Error: Debug;
fn create(
&mut self,
initial_members: Vec<(GroupMember<ID>, Access<C>)>,
) -> Result<M, Self::Error>;
fn receive_from_remote(&mut self, remote_operation: M) -> Result<(), Self::Error>;
fn add(
&mut self,
group_id: ID,
adder: ID,
added: ID,
access: Access<C>,
) -> Result<M, Self::Error>;
fn remove(&mut self, group_id: ID, remover: ID, removed: ID) -> Result<M, Self::Error>;
fn promote(
&mut self,
group_id: ID,
promoter: ID,
promoted: ID,
access: Access<C>,
) -> Result<M, Self::Error>;
fn demote(
&mut self,
group_id: ID,
demoter: ID,
demoted: ID,
access: Access<C>,
) -> Result<M, Self::Error>;
}
pub trait GroupMembership<ID, OP, C> {
type Error: Debug;
fn access(&self, group_id: ID, member: ID) -> Result<Access<C>, Self::Error>;
fn member_ids(&self, group_id: ID) -> Result<HashSet<ID>, Self::Error>;
fn is_member(&self, group_id: ID, member: ID) -> Result<bool, Self::Error>;
fn is_puller(&self, group_id: ID, member: ID) -> Result<bool, Self::Error>;
fn is_reader(&self, group_id: ID, member: ID) -> Result<bool, Self::Error>;
fn is_writer(&self, group_id: ID, member: ID) -> Result<bool, Self::Error>;
fn is_manager(&self, group_id: ID, member: ID) -> Result<bool, Self::Error>;
}