use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, thiserror::Error)]
pub enum PayrollEventError {
#[error("db: {0}")]
Db(#[from] sqlx::Error),
#[error("{0}")]
Other(String),
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PayrollPayable {
pub gl_account_id: Uuid,
pub amount: Decimal,
pub statutory: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PayrollPosted {
pub payroll_entry_id: Uuid,
pub company_id: Uuid,
pub journal_id: Uuid,
pub post_id: Uuid,
pub total_gross: Decimal,
pub total_deductions: Decimal,
pub total_net: Decimal,
pub salary_payable_account_id: Uuid,
pub payables: Vec<PayrollPayable>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum PayrollEvent {
PayrollPosted(PayrollPosted),
}
#[async_trait::async_trait]
pub trait PayrollEventSink: Send + Sync {
async fn publish(&self, event: &PayrollEvent) -> Result<(), PayrollEventError>;
}
#[derive(Debug, Default, Clone)]
pub struct LoggingSink;
#[async_trait::async_trait]
impl PayrollEventSink for LoggingSink {
async fn publish(&self, event: &PayrollEvent) -> Result<(), PayrollEventError> {
tracing::info!(?event, "payroll event");
Ok(())
}
}