use bitflags::*;

bitflags! {
    #[derive(Debug, Clone, Copy)]
    pub struct Perm: i64 {
        // General
        const READ = 0x1;
        // Discussions
        const CREATE_DISCUSSION = 0x2;
        const EDIT_DISCUSSION = 0x4;
        const TAG_DISCUSSION = 0x8;
        // Changes
        const APPLY = 0x10;
        const EDIT_CHANNELS = 0x20;
        // Admin
        const EDIT_TAGS = 0x40;
        const EDIT_PERMISSIONS = 0x80;
    }
}

impl Perm {
    pub fn create_public() -> Self {
        Perm::READ | Perm::CREATE_DISCUSSION
    }
    pub fn create_owner() -> Self {
        Perm::all()
    }
    pub fn from_opt(i: Option<i64>) -> Self {
        i.map(Perm::from_bits_truncate).unwrap_or(Perm::empty())
    }
}