use crate::Database;
use stateset_core::{
ClaimResolution, CreateWarranty, CreateWarrantyClaim, Result, UpdateWarrantyClaim,
Warranty, WarrantyClaim, WarrantyClaimFilter, WarrantyFilter,
};
use std::sync::Arc;
use uuid::Uuid;
pub struct Warranties {
db: Arc<dyn Database>,
}
impl Warranties {
pub(crate) fn new(db: Arc<dyn Database>) -> Self {
Self { db }
}
pub fn create(&self, input: CreateWarranty) -> Result<Warranty> {
self.db.warranties().create(input)
}
pub fn get(&self, id: Uuid) -> Result<Option<Warranty>> {
self.db.warranties().get(id)
}
pub fn get_by_number(&self, warranty_number: &str) -> Result<Option<Warranty>> {
self.db.warranties().get_by_number(warranty_number)
}
pub fn get_by_serial(&self, serial_number: &str) -> Result<Option<Warranty>> {
self.db.warranties().get_by_serial(serial_number)
}
pub fn update(&self, id: Uuid, input: stateset_core::UpdateWarranty) -> Result<Warranty> {
self.db.warranties().update(id, input)
}
pub fn list(&self, filter: WarrantyFilter) -> Result<Vec<Warranty>> {
self.db.warranties().list(filter)
}
pub fn for_customer(&self, customer_id: Uuid) -> Result<Vec<Warranty>> {
self.db.warranties().for_customer(customer_id)
}
pub fn for_order(&self, order_id: Uuid) -> Result<Vec<Warranty>> {
self.db.warranties().for_order(order_id)
}
pub fn expire(&self, id: Uuid) -> Result<Warranty> {
self.db.warranties().expire(id)
}
pub fn void(&self, id: Uuid) -> Result<Warranty> {
self.db.warranties().void(id)
}
pub fn transfer(&self, id: Uuid, new_customer_id: Uuid) -> Result<Warranty> {
self.db.warranties().transfer(id, new_customer_id)
}
pub fn is_valid(&self, id: Uuid) -> Result<bool> {
if let Some(warranty) = self.get(id)? {
Ok(warranty.is_valid())
} else {
Ok(false)
}
}
pub fn create_claim(&self, input: CreateWarrantyClaim) -> Result<WarrantyClaim> {
self.db.warranties().create_claim(input)
}
pub fn get_claim(&self, id: Uuid) -> Result<Option<WarrantyClaim>> {
self.db.warranties().get_claim(id)
}
pub fn get_claim_by_number(&self, claim_number: &str) -> Result<Option<WarrantyClaim>> {
self.db.warranties().get_claim_by_number(claim_number)
}
pub fn update_claim(&self, id: Uuid, input: UpdateWarrantyClaim) -> Result<WarrantyClaim> {
self.db.warranties().update_claim(id, input)
}
pub fn get_claims(&self, warranty_id: Uuid) -> Result<Vec<WarrantyClaim>> {
self.db.warranties().get_claims(warranty_id)
}
pub fn list_claims(&self, filter: WarrantyClaimFilter) -> Result<Vec<WarrantyClaim>> {
self.db.warranties().list_claims(filter)
}
pub fn approve_claim(&self, id: Uuid) -> Result<WarrantyClaim> {
self.db.warranties().approve_claim(id)
}
pub fn deny_claim(&self, id: Uuid, reason: &str) -> Result<WarrantyClaim> {
self.db.warranties().deny_claim(id, reason)
}
pub fn complete_claim(&self, id: Uuid, resolution: ClaimResolution) -> Result<WarrantyClaim> {
self.db.warranties().complete_claim(id, resolution)
}
pub fn cancel_claim(&self, id: Uuid) -> Result<WarrantyClaim> {
self.db.warranties().cancel_claim(id)
}
pub fn count(&self, filter: WarrantyFilter) -> Result<u64> {
self.db.warranties().count(filter)
}
pub fn count_claims(&self, filter: WarrantyClaimFilter) -> Result<u64> {
self.db.warranties().count_claims(filter)
}
}