use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PosSessionOpened {
pub opening_entry_id: Uuid,
pub pos_profile_id: Uuid,
pub company_id: Uuid,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PosInvoicePaid {
pub pos_invoice_id: Uuid,
pub company_id: Uuid,
pub grand_total: Decimal,
pub rounded_total: Decimal,
pub billing_invoice_id: Uuid,
pub payment_id: Uuid,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PosSessionClosed {
pub closing_entry_id: Uuid,
pub opening_entry_id: Uuid,
pub company_id: Uuid,
pub difference_total: Decimal,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PosInvoiceReturned {
pub pos_invoice_id: Uuid,
pub return_ticket_id: Uuid,
pub company_id: Uuid,
pub billing_invoice_id: Uuid,
pub amount: Decimal,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PosTenderCompleted {
pub pos_invoice_id: Uuid,
pub company_id: Uuid,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PosStaleSessionAlerted {
pub opening_entry_id: Uuid,
pub pos_profile_id: Uuid,
pub company_id: Uuid,
pub cashier_party_id: Uuid,
pub opened_at: chrono::NaiveDateTime,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum PosEvent {
PosSessionOpened(PosSessionOpened),
PosTenderCompleted(PosTenderCompleted),
PosInvoicePaid(PosInvoicePaid),
PosSessionClosed(PosSessionClosed),
PosInvoiceReturned(PosInvoiceReturned),
PosStaleSessionAlerted(PosStaleSessionAlerted),
}
pub trait PosEventSink: Send + Sync {
fn publish(&self, event: PosEvent);
}
pub struct LoggingSink;
impl PosEventSink for LoggingSink {
fn publish(&self, event: PosEvent) {
tracing::info!(target: "pos.events", ?event, "pos domain event");
}
}