use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, PartialEq, Eq, Ord, PartialOrd, Clone)] pub enum CorpPermission { Holder, // Implies all permissions. Hire, Fire, Promote, War, Configure, Finance, } impl CorpPermission { pub fn parse(s: &str) -> Option { use CorpPermission::*; match s { "holder" => Some(Holder), "hire" => Some(Hire), "fire" => Some(Fire), "promote" => Some(Promote), "war" => Some(War), "config" | "configure" => Some(Configure), "finance" | "finances" => Some(Finance), _ => None, } } pub fn display(&self) -> &'static str { use CorpPermission::*; match self { Holder => "holder", Hire => "hire", Fire => "fire", Promote => "promote", War => "war", Configure => "configure", Finance => "finance", } } } #[derive(Serialize, Deserialize, PartialEq, Eq, Ord, PartialOrd, Clone)] pub enum CorpCommType { Chat, Notice, Connect, Reward, Death, Consent, } impl CorpCommType { pub fn parse(s: &str) -> Option { use CorpCommType::*; match s { "chat" => Some(Chat), "notice" => Some(Notice), "connect" => Some(Connect), "reward" => Some(Reward), "death" => Some(Death), "consent" => Some(Consent), _ => None, } } pub fn display(&self) -> &'static str { use CorpCommType::*; match self { Chat => "chat", Notice => "notice", Connect => "connect", Reward => "reward", Death => "death", Consent => "consent", } } } pub struct CorpId(pub i64); #[derive(Serialize, Deserialize)] #[serde(default)] pub struct Corp { pub name: String, pub founded: DateTime, // If true, new members get allow_combat on, and members cannot turn // allow_combat off. This will allow duly authorised corp members to // consent to combat with other corps, and have it apply to members. pub allow_combat_required: bool, pub member_permissions: Vec, } impl Default for Corp { fn default() -> Self { Self { name: "Unset".to_owned(), allow_combat_required: false, member_permissions: vec![], founded: Utc::now(), } } } #[derive(Serialize, Deserialize)] #[serde(default)] pub struct CorpMembership { pub invited_at: Option>, pub joined_at: Option>, pub permissions: Vec, pub allow_combat: bool, pub job_title: String, pub priority: i64, pub comms_on: Vec, } impl Default for CorpMembership { fn default() -> CorpMembership { use CorpCommType::*; CorpMembership { invited_at: None, joined_at: None, permissions: vec![], allow_combat: false, job_title: "Employee".to_owned(), priority: 100, comms_on: vec![Chat, Notice, Connect, Reward, Death, Consent], } } }