db/specs/models_marketplace/main/product.v
2025-08-08 09:42:47 +02:00

178 lines
4.0 KiB
V

module main
import freeflowuniverse.herolib.hero.models.marketplace.core
// Generic product structure that can represent any marketplace item
pub struct Product {
core.Base
pub mut:
id string
name string
category_id string // References ProductCategory config
description string
base_price f64 // Using f64 for Decimal
base_currency string
attributes map[string]ProductAttribute // Generic attributes
provider_id string
provider_name string
availability ProductAvailability
metadata ProductMetadata // Extensible metadata
created_at u64 // Unix timestamp
updated_at u64 // Unix timestamp
}
// Configurable product categories
pub struct ProductCategory {
pub mut:
id string
name string
display_name string
description string
attribute_schema []AttributeDefinition // Defines allowed attributes
parent_category string
is_active bool
}
// Generic attribute system for any product type
pub struct ProductAttribute {
pub mut:
key string
value string // Using string for serde_json::Value, consider map[string]string or specific types
attribute_type AttributeType
is_searchable bool
is_filterable bool
display_order u32
}
pub enum AttributeType {
text
number
slice_configuration
boolean
select // Select(Vec<String>)
multi_select // MultiSelect(Vec<String>)
range // Range { min: f64, max: f64 }
custom
}
pub struct AttributeDefinition {
pub mut:
key string
name string
attribute_type AttributeType
is_required bool
is_searchable bool
is_filterable bool
validation_rules []ValidationRule
}
pub enum ValidationRule {
min_length // MinLength(usize)
max_length // MaxLength(usize)
min_value // MinValue(f64)
max_value // MaxValue(f64)
pattern // Pattern(String)
custom
}
pub enum ProductAvailability {
available
limited
unavailable
pre_order
custom
}
pub struct ProductMetadata {
pub mut:
tags []string
location string
rating f32
review_count u32
featured bool
custom_fields map[string]string // Using map[string]string for HashMap<String, serde_json::Value>
}
// Support for different pricing models
pub enum PricingModel {
one_time
recurring // Recurring { interval: String }
usage_based // UsageBased { unit: String }
tiered // Tiered(Vec<PriceTier>)
custom
}
pub struct PriceTier {
pub mut:
min_quantity u32
max_quantity u32
price_per_unit f64 // Using f64 for Decimal
discount_percentage f32
}
// Slice configuration data structure for product attributes
pub struct SliceConfiguration {
pub mut:
cpu_cores int
memory_gb int
storage_gb int
bandwidth_mbps int
min_uptime_sla f32
public_ips int
node_id string
slice_type SliceType
pricing SlicePricing
}
// Enhanced pricing structure for slices with multiple time periods
pub struct SlicePricing {
pub mut:
hourly f64 // Using f64 for Decimal
daily f64 // Using f64 for Decimal
monthly f64 // Using f64 for Decimal
yearly f64 // Using f64 for Decimal
}
pub enum SliceType {
basic
standard
premium
custom
}
// Placeholder for SliceAllocation and SliceCombination
// These are not directly from product.rs but are referenced in user.rs
pub struct SliceAllocation {
pub mut:
slice_id string
node_id string
user_id string
allocated_cpu_cores int
allocated_memory_gb int
allocated_storage_gb int
allocated_bandwidth_mbps int
start_time u64
end_time u64
}
pub struct SliceCombination {
pub mut:
cpu_cores int
memory_gb int
storage_gb int
bandwidth_mbps int
price_per_hour f64
}
// Placeholder for DefaultSliceFormat
// This is not directly from product.rs but is referenced in user.rs
pub struct DefaultSliceFormat {
pub mut:
name string
cpu_cores int
memory_gb int
storage_gb int
bandwidth_mbps int
price_per_hour f64
}