use stateset_core::{
BulkSupplierSkuItem, CreateSupplierSku, Result, SupplierSku, SupplierSkuFilter, SupplierSkuId,
UpdateSupplierSku,
};
use stateset_db::{Database, DatabaseCapability};
use std::sync::Arc;
use uuid::Uuid;
pub struct SupplierSkus {
db: Arc<dyn Database>,
}
impl std::fmt::Debug for SupplierSkus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("SupplierSkus").finish_non_exhaustive()
}
}
impl SupplierSkus {
pub(crate) fn new(db: Arc<dyn Database>) -> Self {
Self { db }
}
#[must_use]
pub fn is_supported(&self) -> bool {
self.db.supports_capability(DatabaseCapability::SupplierSkus)
}
fn ensure(&self) -> Result<()> {
self.db.ensure_capability(DatabaseCapability::SupplierSkus)
}
pub fn create(&self, input: CreateSupplierSku) -> Result<SupplierSku> {
self.ensure()?;
self.db.supplier_skus().create(input)
}
pub fn get(&self, id: SupplierSkuId) -> Result<Option<SupplierSku>> {
self.ensure()?;
self.db.supplier_skus().get(id)
}
pub fn update(&self, id: SupplierSkuId, input: UpdateSupplierSku) -> Result<SupplierSku> {
self.ensure()?;
self.db.supplier_skus().update(id, input)
}
pub fn list(&self, filter: SupplierSkuFilter) -> Result<Vec<SupplierSku>> {
self.ensure()?;
self.db.supplier_skus().list(filter)
}
pub fn delete(&self, id: SupplierSkuId) -> Result<()> {
self.ensure()?;
self.db.supplier_skus().delete(id)
}
pub fn bulk_upsert(&self, supplier_id: Uuid, items: Vec<BulkSupplierSkuItem>) -> Result<u64> {
self.ensure()?;
self.db.supplier_skus().bulk_upsert(supplier_id, items)
}
}