use async_trait::async_trait;
use uuid::Uuid;
#[derive(Debug, Clone, serde::Serialize)]
pub struct HierarchyNode {
pub id: Uuid,
pub parent_id: Option<Uuid>,
pub code: Option<String>,
pub name: String,
pub level: i32,
}
#[derive(Debug, Clone, Copy)]
pub enum HierarchyTable {
Account,
CostCenter,
FiscalPeriod,
}
impl HierarchyTable {
pub fn table(self) -> &'static str {
match self {
Self::Account => "accounting.accounts",
Self::CostCenter => "accounting.cost_centers",
Self::FiscalPeriod => "accounting.fiscal_periods",
}
}
pub fn code_column(self) -> &'static str {
match self {
Self::Account => "account_number",
Self::CostCenter => "code",
Self::FiscalPeriod => "period_code",
}
}
}
#[async_trait]
pub trait HierarchyRepository: Send + Sync {
async fn ancestors(
&self,
table: HierarchyTable,
id: Uuid,
) -> anyhow::Result<Vec<HierarchyNode>>;
}