use crate::ids::{ActorId, LedgerEntryId, TenantId};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Role {
Operator,
Auditor,
Gatekeeper,
Custom(String),
}
impl Role {
pub fn custom(name: impl Into<String>) -> Result<Self, String> {
let name = name.into();
if name.is_empty() {
return Err("custom role name must be non-empty".to_string());
}
Ok(Role::Custom(name))
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Capability {
CanSubmit,
CanExecute,
CanReview,
CanApprove,
CanCancel,
Custom(String),
}
impl Capability {
pub fn custom(name: impl Into<String>) -> Result<Self, String> {
let name = name.into();
if name.is_empty() {
return Err("custom capability name must be non-empty".to_string());
}
Ok(Capability::Custom(name))
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TenantRegistration {
tenant_id: TenantId,
name: String,
}
impl TenantRegistration {
pub fn new(tenant_id: TenantId, name: impl Into<String>) -> Self {
let name = name.into();
assert!(!name.is_empty(), "tenant name must be non-empty");
TenantRegistration { tenant_id, name }
}
pub fn tenant_id(&self) -> TenantId {
self.tenant_id
}
pub fn name(&self) -> &str {
&self.name
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct LedgerEntry {
entry_id: LedgerEntryId,
tenant_id: TenantId,
ledger_key: String,
actor_id: Option<ActorId>,
payload: Vec<u8>,
timestamp: u64,
}
impl LedgerEntry {
pub fn new(
entry_id: LedgerEntryId,
tenant_id: TenantId,
ledger_key: impl Into<String>,
payload: Vec<u8>,
timestamp: u64,
) -> Self {
let ledger_key = ledger_key.into();
assert!(!ledger_key.is_empty(), "ledger_key must be non-empty");
LedgerEntry { entry_id, tenant_id, ledger_key, actor_id: None, payload, timestamp }
}
pub fn with_actor(mut self, actor_id: ActorId) -> Self {
self.actor_id = Some(actor_id);
self
}
pub fn entry_id(&self) -> LedgerEntryId {
self.entry_id
}
pub fn tenant_id(&self) -> TenantId {
self.tenant_id
}
pub fn ledger_key(&self) -> &str {
&self.ledger_key
}
pub fn actor_id(&self) -> Option<ActorId> {
self.actor_id
}
pub fn payload(&self) -> &[u8] {
&self.payload
}
pub fn timestamp(&self) -> u64 {
self.timestamp
}
}