#![allow(dead_code)]
use serde::{Deserialize, Serialize};
use std::fmt;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum Permission {
    Read,
    Write,
    Delete,
    Share,
    Admin,
}

impl fmt::Display for Permission {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Read => write!(f, "read"),
            Self::Write => write!(f, "write"),
            Self::Delete => write!(f, "delete"),
            Self::Share => write!(f, "share"),
            Self::Admin => write!(f, "admin"),
        }
    }
}

impl Permission {
    pub fn can_read(&self) -> bool {
        matches!(self, Self::Read | Self::Admin)
    }

    pub fn can_write(&self) -> bool {
        matches!(self, Self::Write | Self::Admin)
    }

    pub fn can_delete(&self) -> bool {
        matches!(self, Self::Delete | Self::Admin)
    }

    pub fn can_share(&self) -> bool {
        matches!(self, Self::Share | Self::Admin)
    }
}

pub type Permissions = Vec<Permission>;
