150 lines
3.8 KiB
Rust
150 lines
3.8 KiB
Rust
use serde::{Serialize, Deserialize};
|
|
use heromodels_core::BaseModelData;
|
|
use heromodels_core::Model;
|
|
use heromodels_core::BaseModelDataOps;
|
|
use heromodels_derive::model;
|
|
|
|
// ProductType represents the type of a product
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
|
|
pub enum ProductType {
|
|
#[default]
|
|
Product,
|
|
Service,
|
|
}
|
|
|
|
// ProductStatus represents the status of a product
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
|
|
pub enum ProductStatus {
|
|
#[default]
|
|
Available,
|
|
Unavailable,
|
|
}
|
|
|
|
// ProductComponent represents a component or sub-part of a product.
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
|
|
pub struct ProductComponent {
|
|
pub name: String,
|
|
pub description: String,
|
|
pub quantity: u32,
|
|
}
|
|
|
|
impl ProductComponent {
|
|
// Minimal constructor with no parameters
|
|
pub fn new() -> Self {
|
|
Self {
|
|
name: String::new(),
|
|
description: String::new(),
|
|
quantity: 1, // Default quantity to 1
|
|
}
|
|
}
|
|
|
|
// Builder methods
|
|
pub fn description(mut self, description: impl ToString) -> Self {
|
|
self.description = description.to_string();
|
|
self
|
|
}
|
|
|
|
pub fn quantity(mut self, quantity: u32) -> Self {
|
|
self.quantity = quantity;
|
|
self
|
|
}
|
|
|
|
pub fn name(mut self, name: impl ToString) -> Self {
|
|
self.name = name.to_string();
|
|
self
|
|
}
|
|
}
|
|
|
|
// Product represents a product or service offered
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
|
|
#[model]
|
|
pub struct Product {
|
|
pub base_data: BaseModelData,
|
|
pub name: String,
|
|
pub description: String,
|
|
pub price: f64, // Representing currency.Currency for now
|
|
pub type_: ProductType,
|
|
pub category: String,
|
|
pub status: ProductStatus,
|
|
pub max_amount: u16,
|
|
pub purchase_till: i64, // Representing ourtime.OurTime
|
|
pub active_till: i64, // Representing ourtime.OurTime
|
|
pub components: Vec<ProductComponent>,
|
|
}
|
|
|
|
impl Product {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
base_data: BaseModelData::new(),
|
|
name: String::new(),
|
|
description: String::new(),
|
|
price: 0.0,
|
|
type_: ProductType::default(),
|
|
category: String::new(),
|
|
status: ProductStatus::default(),
|
|
max_amount: 0,
|
|
purchase_till: 0,
|
|
active_till: 0,
|
|
components: Vec::new(),
|
|
}
|
|
}
|
|
|
|
// Builder methods
|
|
pub fn name(mut self, name: impl ToString) -> Self {
|
|
self.name = name.to_string();
|
|
self
|
|
}
|
|
|
|
pub fn description(mut self, description: impl ToString) -> Self {
|
|
self.description = description.to_string();
|
|
self
|
|
}
|
|
|
|
pub fn price(mut self, price: f64) -> Self {
|
|
self.price = price;
|
|
self
|
|
}
|
|
|
|
pub fn type_(mut self, type_: ProductType) -> Self {
|
|
self.type_ = type_;
|
|
self
|
|
}
|
|
|
|
pub fn category(mut self, category: impl ToString) -> Self {
|
|
self.category = category.to_string();
|
|
self
|
|
}
|
|
|
|
pub fn status(mut self, status: ProductStatus) -> Self {
|
|
self.status = status;
|
|
self
|
|
}
|
|
|
|
pub fn max_amount(mut self, max_amount: u16) -> Self {
|
|
self.max_amount = max_amount;
|
|
self
|
|
}
|
|
|
|
pub fn purchase_till(mut self, purchase_till: i64) -> Self {
|
|
self.purchase_till = purchase_till;
|
|
self
|
|
}
|
|
|
|
pub fn active_till(mut self, active_till: i64) -> Self {
|
|
self.active_till = active_till;
|
|
self
|
|
}
|
|
|
|
pub fn add_component(mut self, component: ProductComponent) -> Self {
|
|
self.components.push(component);
|
|
self
|
|
}
|
|
|
|
pub fn components(mut self, components: Vec<ProductComponent>) -> Self {
|
|
self.components = components;
|
|
self
|
|
}
|
|
|
|
// BaseModelData field operations are now handled by BaseModelDataOps trait
|
|
}
|