731 lines
16 KiB
V
731 lines
16 KiB
V
module main
|
|
|
|
import freeflowuniverse.herolib.hero.models.marketplace.core
|
|
|
|
// Represents a user in the system
|
|
pub struct User {
|
|
core.Base
|
|
pub mut:
|
|
id u32 // Unique identifier for the user, using u32 for consistency with VLang
|
|
name string // User's full name
|
|
email string // User's email address
|
|
role UserRole // User's role in the system
|
|
country string // User's country
|
|
timezone string // User's timezone
|
|
created_at u64 // Unix timestamp of creation
|
|
updated_at u64 // Unix timestamp of last update
|
|
mock_data MockUserData // Mock data for dashboard
|
|
}
|
|
|
|
// Represents the possible roles a user can have
|
|
pub enum UserRole {
|
|
user
|
|
admin
|
|
}
|
|
|
|
// Represents user login credentials
|
|
pub struct LoginCredentials {
|
|
pub mut:
|
|
email string
|
|
password string
|
|
}
|
|
|
|
// Represents user registration data
|
|
pub struct RegistrationData {
|
|
pub mut:
|
|
name string
|
|
email string
|
|
password string
|
|
password_confirmation string
|
|
}
|
|
|
|
// Mock user data for testing
|
|
pub struct MockUserData {
|
|
pub mut:
|
|
active_deployments int
|
|
active_slices int
|
|
current_cost int
|
|
balance int
|
|
wallet_balance_usd f64 // Using f64 for Decimal, consider string for high precision
|
|
owned_product_ids []string
|
|
active_rentals []string
|
|
transaction_history []Transaction
|
|
resource_utilization ResourceUtilization
|
|
usd_usage_trend []int
|
|
user_activity UserActivityStats
|
|
recent_activities []RecentActivity
|
|
deployment_distribution DeploymentDistribution
|
|
farmer_data FarmerData // Farmer-specific data
|
|
app_provider_data AppProviderData // App Provider-specific data
|
|
service_provider_data ServiceProviderData // Service Provider-specific data
|
|
customer_service_data CustomerServiceData // Customer Service-specific data
|
|
}
|
|
|
|
pub struct ResourceUtilization {
|
|
pub mut:
|
|
cpu int
|
|
memory int
|
|
storage int
|
|
network int
|
|
}
|
|
|
|
pub struct UserActivityStats {
|
|
pub mut:
|
|
deployments []int
|
|
resource_reservations []int
|
|
}
|
|
|
|
pub struct RecentActivity {
|
|
pub mut:
|
|
date string
|
|
action string
|
|
status string
|
|
details string
|
|
}
|
|
|
|
pub struct DeploymentDistribution {
|
|
pub mut:
|
|
regions []RegionDeployments
|
|
}
|
|
|
|
pub struct RegionDeployments {
|
|
pub mut:
|
|
region string
|
|
nodes int
|
|
slices int
|
|
apps int
|
|
gateways int
|
|
}
|
|
|
|
// Farmer-specific data
|
|
pub struct FarmerData {
|
|
pub mut:
|
|
total_nodes int
|
|
online_nodes int
|
|
total_capacity NodeCapacity
|
|
used_capacity NodeCapacity
|
|
monthly_earnings_usd int
|
|
total_earnings_usd int
|
|
uptime_percentage f32
|
|
nodes []FarmNode
|
|
earnings_history []EarningsRecord
|
|
slice_templates []Product
|
|
active_slices int
|
|
}
|
|
|
|
pub struct NodeCapacity {
|
|
pub mut:
|
|
cpu_cores int
|
|
memory_gb int
|
|
storage_gb int
|
|
bandwidth_mbps int
|
|
ssd_storage_gb int
|
|
hdd_storage_gb int
|
|
}
|
|
|
|
// Enhanced Node structure for farmer dashboard with modern types
|
|
pub struct FarmNode {
|
|
pub mut:
|
|
id string
|
|
name string
|
|
location string
|
|
status NodeStatus
|
|
capacity NodeCapacity
|
|
used_capacity NodeCapacity
|
|
uptime_percentage f32
|
|
earnings_today_usd f64 // Using f64 for Decimal
|
|
last_seen u64 // Unix timestamp
|
|
health_score f32
|
|
region string
|
|
node_type string
|
|
slice_formats []string
|
|
rental_options NodeRentalOptions
|
|
availability_status NodeAvailabilityStatus
|
|
grid_node_id u32
|
|
grid_data GridNodeData
|
|
node_group_id string
|
|
group_assignment_date u64 // Unix timestamp
|
|
group_slice_format string
|
|
group_slice_price f64 // Using f64 for Decimal
|
|
staking_options NodeStakingOptions
|
|
marketplace_sla MarketplaceSLA
|
|
total_base_slices u32
|
|
allocated_base_slices u32
|
|
slice_allocations []SliceAllocation // Assuming SliceAllocation is defined elsewhere or will be translated
|
|
available_combinations []SliceCombination // Assuming SliceCombination is defined elsewhere or will be translated
|
|
slice_pricing SlicePricing // Assuming SlicePricing is defined elsewhere or will be translated
|
|
slice_last_calculated u64 // Unix timestamp
|
|
}
|
|
|
|
pub struct EarningsRecord {
|
|
pub mut:
|
|
date string
|
|
amount int
|
|
source string
|
|
}
|
|
|
|
pub enum NodeStatus {
|
|
online
|
|
offline
|
|
maintenance
|
|
error
|
|
standby
|
|
}
|
|
|
|
pub struct FarmerSettings {
|
|
pub mut:
|
|
auto_accept_deployments bool
|
|
maintenance_window string
|
|
notification_preferences NotificationSettings
|
|
minimum_deployment_duration int
|
|
preferred_regions []string
|
|
default_slice_customizations map[string]DefaultSliceFormat // Assuming DefaultSliceFormat is defined elsewhere or will be translated
|
|
}
|
|
|
|
pub struct NotificationSettings {
|
|
pub mut:
|
|
email_enabled bool
|
|
sms_enabled bool
|
|
push bool
|
|
node_offline_alerts bool
|
|
earnings_reports bool
|
|
maintenance_reminders bool
|
|
}
|
|
|
|
// Marketplace SLA configuration - what the farmer promises to customers
|
|
pub struct MarketplaceSLA {
|
|
pub mut:
|
|
uptime_guarantee_percentage f32
|
|
bandwidth_guarantee_mbps int
|
|
base_slice_price f64 // Using f64 for Decimal
|
|
last_updated u64 // Unix timestamp
|
|
}
|
|
|
|
// Node rental options that farmers can configure
|
|
pub struct NodeRentalOptions {
|
|
pub mut:
|
|
slice_rental_enabled bool
|
|
full_node_rental_enabled bool
|
|
full_node_pricing FullNodePricing
|
|
minimum_rental_days u32
|
|
maximum_rental_days u32
|
|
auto_renewal_enabled bool
|
|
}
|
|
|
|
// Node staking options that farmers can configure
|
|
pub struct NodeStakingOptions {
|
|
pub mut:
|
|
staking_enabled bool
|
|
staked_amount f64 // Using f64 for Decimal
|
|
staking_start_date u64 // Unix timestamp
|
|
staking_period_months u32
|
|
early_withdrawal_allowed bool
|
|
early_withdrawal_penalty_percent f32
|
|
}
|
|
|
|
// Full node rental pricing configuration with auto-calculation support
|
|
pub struct FullNodePricing {
|
|
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
|
|
auto_calculate bool
|
|
daily_discount_percent f32
|
|
monthly_discount_percent f32
|
|
yearly_discount_percent f32
|
|
}
|
|
|
|
// Node availability status for rental management
|
|
pub enum NodeAvailabilityStatus {
|
|
available
|
|
partially_rented
|
|
fully_rented
|
|
unavailable
|
|
reserved
|
|
}
|
|
|
|
// Individual node rental record
|
|
pub struct NodeRental {
|
|
pub mut:
|
|
id string
|
|
node_id string
|
|
renter_email string
|
|
rental_type NodeRentalType
|
|
monthly_cost f64 // Using f64 for Decimal
|
|
start_date u64 // Unix timestamp
|
|
end_date u64 // Unix timestamp
|
|
status NodeRentalStatus
|
|
auto_renewal bool
|
|
payment_method string
|
|
metadata map[string]string // Using map[string]string for HashMap<String, serde_json::Value>
|
|
}
|
|
|
|
// Type of node rental
|
|
pub enum NodeRentalType {
|
|
slice // Slice { slice_ids: Vec<String>, total_cpu_cores: u32, total_memory_gb: u32, total_storage_gb: u32 }
|
|
full_node
|
|
}
|
|
|
|
// Status of a node rental
|
|
pub enum NodeRentalStatus {
|
|
active
|
|
pending
|
|
expired
|
|
cancelled
|
|
suspended
|
|
}
|
|
|
|
// Farmer earnings from node rentals
|
|
pub struct FarmerRentalEarning {
|
|
pub mut:
|
|
id string
|
|
node_id string
|
|
rental_id string
|
|
renter_email string
|
|
amount f64 // Using f64 for Decimal
|
|
currency string
|
|
earning_date u64 // Unix timestamp
|
|
rental_type NodeRentalType
|
|
payment_status PaymentStatus
|
|
}
|
|
|
|
pub enum PaymentStatus {
|
|
pending
|
|
completed
|
|
failed
|
|
refunded
|
|
}
|
|
|
|
// User Activity Tracking
|
|
pub struct UserActivity {
|
|
pub mut:
|
|
id string
|
|
activity_type ActivityType
|
|
description string
|
|
timestamp u64 // Unix timestamp
|
|
metadata map[string]string // Using map[string]string for HashMap<String, serde_json::Value>
|
|
category string
|
|
importance ActivityImportance
|
|
}
|
|
|
|
pub enum ActivityType {
|
|
login
|
|
purchase
|
|
deployment
|
|
service_created
|
|
app_published
|
|
node_added
|
|
node_updated
|
|
wallet_transaction
|
|
profile_update
|
|
settings_change
|
|
marketplace_view
|
|
slice_created
|
|
slice_allocated
|
|
slice_released
|
|
slice_rental_started
|
|
slice_rental_stopped
|
|
slice_rental_restarted
|
|
slice_rental_cancelled
|
|
}
|
|
|
|
pub enum ActivityImportance {
|
|
low
|
|
medium
|
|
high
|
|
critical
|
|
}
|
|
|
|
// Enhanced User Statistics
|
|
pub struct UsageStatistics {
|
|
pub mut:
|
|
total_deployments int
|
|
active_services int
|
|
total_spent f64 // Using f64 for Decimal
|
|
favorite_categories []string
|
|
usage_trends []UsageTrend
|
|
login_frequency f32
|
|
preferred_regions []string
|
|
account_age_days int
|
|
last_activity u64 // Unix timestamp
|
|
}
|
|
|
|
pub struct UsageTrend {
|
|
pub mut:
|
|
period string
|
|
metric string
|
|
value f32
|
|
change_percentage f32
|
|
}
|
|
|
|
pub struct UserPreferences {
|
|
pub mut:
|
|
preferred_currency string
|
|
preferred_language string
|
|
timezone string
|
|
dashboard_layout string
|
|
notification_settings NotificationSettings
|
|
privacy_settings PrivacySettings
|
|
theme string
|
|
last_payment_method string
|
|
}
|
|
|
|
pub struct PrivacySettings {
|
|
pub mut:
|
|
profile_visibility string
|
|
activity_tracking bool
|
|
marketing_emails bool
|
|
data_sharing bool
|
|
}
|
|
|
|
// ThreeFold Grid Node Data fetched from gridproxy/graphql
|
|
pub struct GridNodeData {
|
|
pub mut:
|
|
grid_node_id u32
|
|
city string
|
|
country string
|
|
farm_name string
|
|
farm_id u32
|
|
public_ips u32
|
|
total_resources NodeCapacity
|
|
used_resources NodeCapacity
|
|
certification_type string
|
|
farming_policy_id u32
|
|
last_updated u64 // Unix timestamp
|
|
}
|
|
|
|
// Node Group for managing multiple nodes together
|
|
pub struct NodeGroup {
|
|
core.Base
|
|
pub mut:
|
|
id string
|
|
name string
|
|
description string
|
|
group_type NodeGroupType
|
|
node_ids []string
|
|
group_config NodeGroupConfig
|
|
created_at u64 // Unix timestamp
|
|
updated_at u64 // Unix timestamp
|
|
}
|
|
|
|
// Type of node group - default or custom
|
|
pub enum NodeGroupType {
|
|
default_compute
|
|
default_storage
|
|
default_ai_gpu
|
|
custom
|
|
}
|
|
|
|
// Configuration for node groups
|
|
pub struct NodeGroupConfig {
|
|
pub mut:
|
|
preferred_slice_formats []string
|
|
default_pricing map[string]f64 // Using f64 for Decimal
|
|
resource_optimization ResourceOptimization
|
|
auto_scaling bool
|
|
}
|
|
|
|
// Resource optimization settings for groups
|
|
pub enum ResourceOptimization {
|
|
balanced
|
|
performance
|
|
efficiency
|
|
custom
|
|
}
|
|
|
|
// Statistics for a node group
|
|
pub struct GroupStatistics {
|
|
pub mut:
|
|
group_id string
|
|
total_nodes int
|
|
online_nodes int
|
|
total_capacity NodeCapacity
|
|
average_uptime f32
|
|
group_type NodeGroupType
|
|
}
|
|
|
|
// Enhanced User Dashboard Data
|
|
pub struct UserDashboardData {
|
|
pub mut:
|
|
user_info UserInfo
|
|
recent_activities []UserActivity
|
|
usage_statistics UsageStatistics
|
|
active_services []Service // Assuming Service is defined elsewhere or will be translated
|
|
active_deployments int
|
|
wallet_summary WalletSummary
|
|
recommendations []Recommendation
|
|
quick_actions []QuickAction
|
|
}
|
|
|
|
pub struct UserInfo {
|
|
pub mut:
|
|
name string
|
|
email string
|
|
member_since string
|
|
account_type string
|
|
verification_status string
|
|
}
|
|
|
|
pub struct WalletSummary {
|
|
pub mut:
|
|
balance f64 // Using f64 for Decimal
|
|
currency string
|
|
recent_transactions int
|
|
pending_transactions int
|
|
}
|
|
|
|
pub struct Recommendation {
|
|
pub mut:
|
|
id string
|
|
title string
|
|
description string
|
|
action_url string
|
|
priority string
|
|
category string
|
|
}
|
|
|
|
pub struct QuickAction {
|
|
pub mut:
|
|
id string
|
|
title string
|
|
description string
|
|
action_url string
|
|
icon string
|
|
enabled bool
|
|
}
|
|
|
|
// App Provider-specific data
|
|
pub struct AppProviderData {
|
|
pub mut:
|
|
published_apps int
|
|
total_deployments int
|
|
active_deployments int
|
|
monthly_revenue_usd int
|
|
total_revenue_usd int
|
|
apps []PublishedApp
|
|
deployment_stats []DeploymentStat
|
|
revenue_history []RevenueRecord
|
|
}
|
|
|
|
pub struct PublishedApp {
|
|
pub mut:
|
|
id string
|
|
name string
|
|
category string
|
|
version string
|
|
status string
|
|
deployments int
|
|
rating f32
|
|
monthly_revenue_usd int
|
|
last_updated string
|
|
auto_healing bool
|
|
}
|
|
|
|
pub struct DeploymentStat {
|
|
pub mut:
|
|
app_name string
|
|
region string
|
|
instances int
|
|
status string
|
|
resource_usage ResourceUtilization
|
|
customer_name string
|
|
deployed_date string
|
|
deployment_id string
|
|
auto_healing bool
|
|
}
|
|
|
|
pub struct RevenueRecord {
|
|
pub mut:
|
|
date string
|
|
amount int
|
|
app_name string
|
|
}
|
|
|
|
// Service Provider-specific data
|
|
pub struct ServiceProviderData {
|
|
pub mut:
|
|
active_services int
|
|
total_clients int
|
|
monthly_revenue_usd int
|
|
total_revenue_usd int
|
|
service_rating f32
|
|
services []Service
|
|
client_requests []ServiceRequest
|
|
revenue_history []RevenueRecord
|
|
}
|
|
|
|
pub struct Service {
|
|
pub mut:
|
|
id string
|
|
name string
|
|
category string
|
|
description string
|
|
price_per_hour_usd int
|
|
status string
|
|
clients int
|
|
rating f32
|
|
total_hours int
|
|
}
|
|
|
|
pub struct ServiceRequest {
|
|
pub mut:
|
|
id string
|
|
client_name string
|
|
service_name string
|
|
status string
|
|
requested_date string
|
|
estimated_hours int
|
|
budget int
|
|
priority string
|
|
progress int
|
|
completed_date string
|
|
client_email string
|
|
client_phone string
|
|
description string
|
|
created_date string
|
|
}
|
|
|
|
// Service booking record for customers who purchase services
|
|
pub struct ServiceBooking {
|
|
pub mut:
|
|
id string
|
|
service_id string
|
|
service_name string
|
|
provider_email string
|
|
customer_email string
|
|
budget int
|
|
estimated_hours int
|
|
status string
|
|
requested_date string
|
|
priority string
|
|
description string
|
|
booking_date string
|
|
client_phone string
|
|
progress int
|
|
completed_date string
|
|
}
|
|
|
|
// Customer Service-specific data (for users who book services)
|
|
pub struct CustomerServiceData {
|
|
pub mut:
|
|
active_bookings int
|
|
completed_bookings int
|
|
total_spent int
|
|
monthly_spending int
|
|
average_rating_given f32
|
|
service_bookings []ServiceBooking
|
|
favorite_providers []string
|
|
spending_history []SpendingRecord
|
|
}
|
|
|
|
pub struct SpendingRecord {
|
|
pub mut:
|
|
date string
|
|
amount int
|
|
service_name string
|
|
provider_name string
|
|
}
|
|
|
|
// Transaction record for wallet operations
|
|
pub struct Transaction {
|
|
pub mut:
|
|
id string
|
|
user_id string
|
|
transaction_type TransactionType
|
|
amount f64 // Using f64 for Decimal
|
|
timestamp u64 // Unix timestamp
|
|
status TransactionStatus
|
|
}
|
|
|
|
// Types of transactions
|
|
pub enum TransactionType {
|
|
purchase
|
|
rental
|
|
transfer
|
|
earning
|
|
instant_purchase
|
|
exchange
|
|
stake
|
|
unstake
|
|
auto_top_up
|
|
credits_purchase
|
|
credits_sale
|
|
credits_transfer
|
|
}
|
|
|
|
// Transaction status
|
|
pub enum TransactionStatus {
|
|
pending
|
|
completed
|
|
failed
|
|
cancelled
|
|
}
|
|
|
|
// Rental record
|
|
pub struct Rental {
|
|
pub mut:
|
|
id string
|
|
user_id string
|
|
product_id string
|
|
start_date u64 // Unix timestamp
|
|
end_date u64 // Unix timestamp
|
|
status RentalStatus
|
|
monthly_cost f64 // Using f64 for Decimal
|
|
}
|
|
|
|
// Rental status
|
|
pub enum RentalStatus {
|
|
active
|
|
expired
|
|
cancelled
|
|
pending
|
|
}
|
|
|
|
// User deployment information for dashboard
|
|
pub struct UserDeployment {
|
|
pub mut:
|
|
id string
|
|
app_name string
|
|
status DeploymentStatus
|
|
cost_per_month f64 // Using f64 for Decimal
|
|
deployed_at u64 // Unix timestamp
|
|
provider string
|
|
region string
|
|
resource_usage ResourceUtilization
|
|
}
|
|
|
|
// Deployment status enum
|
|
pub enum DeploymentStatus {
|
|
active
|
|
pending
|
|
stopped
|
|
error
|
|
maintenance
|
|
}
|
|
|
|
// Comprehensive user metrics for dashboard
|
|
pub struct UserMetrics {
|
|
pub mut:
|
|
total_spent_this_month f64 // Using f64 for Decimal
|
|
active_deployments_count int
|
|
resource_utilization ResourceUtilization
|
|
cost_trend []int
|
|
wallet_balance f64 // Using f64 for Decimal
|
|
total_transactions int
|
|
}
|
|
|
|
// User compute resource for dashboard display
|
|
pub struct UserComputeResource {
|
|
pub mut:
|
|
id string
|
|
resource_type string
|
|
specs string
|
|
location string
|
|
status string
|
|
sla string
|
|
monthly_cost f64 // Using f64 for Decimal
|
|
provider string
|
|
resource_usage ResourceUtilization
|
|
}
|