use uuid::Uuid;

use crate::errors::AccessError;

pub mod portal;
pub mod workspace;

#[derive(Clone, Copy, Debug, PartialEq, strum::Display, strum::EnumIs)]
pub enum Actor {
    /// Bypass explicit auth checks.
    Bypass,

    #[strum(to_string = "User({0})")]
    User(Uuid),
}

/// Provides methods for fetching database entities of type `T`, typically with
/// authorization checks.
pub trait Accessor<T>: Default + Sized {
    /// Returns a new builder struct. Alias for [`Self::default()`].
    fn new() -> Self {
        Self::default()
    }

    /// Fetch an entity from the database, returning [`AccessError::NotFound`]
    /// if access is denied or the object cannot be found.
    fn fetch_one(self) -> impl Future<Output = Result<T, AccessError>>;
}
