1use crate::Vector;
4use chrono::{DateTime, Utc};
5use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct CustomerEmbedding {
11 pub customer_id: String,
13 pub name: String,
15 pub segment: CustomerSegment,
17 pub purchase_history: Vec<Purchase>,
19 pub preferences: CustomerPreferences,
21 pub behavior_metrics: BehaviorMetrics,
23 pub embedding: Vector,
25 pub predicted_ltv: f64,
27 pub churn_risk: f64,
29 pub recommendations: Vec<ProductRecommendation>,
31 pub last_updated: DateTime<Utc>,
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
37pub enum CustomerSegment {
38 HighValue,
39 Regular,
40 Occasional,
41 NewCustomer,
42 AtRisk,
43 Churned,
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct Purchase {
49 pub product_id: String,
51 pub purchase_date: DateTime<Utc>,
53 pub quantity: u32,
55 pub price: f64,
57 pub channel: PurchaseChannel,
59 pub satisfaction: Option<u8>,
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
65pub enum PurchaseChannel {
66 Online,
67 InStore,
68 Mobile,
69 Phone,
70 ThirdParty,
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct CustomerPreferences {
76 pub preferred_categories: Vec<String>,
78 pub price_sensitivity: f64,
80 pub brand_loyalty: HashMap<String, f64>,
82 pub preferred_channels: Vec<PurchaseChannel>,
84 pub communication_preferences: CommunicationPreferences,
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
90pub struct CommunicationPreferences {
91 pub email_opt_in: bool,
93 pub sms_opt_in: bool,
95 pub frequency: CommunicationFrequency,
97 pub content_types: Vec<String>,
99}
100
101#[derive(Debug, Clone, Serialize, Deserialize)]
103pub enum CommunicationFrequency {
104 Daily,
105 Weekly,
106 Monthly,
107 Quarterly,
108 Never,
109}
110
111#[derive(Debug, Clone, Serialize, Deserialize)]
113pub struct BehaviorMetrics {
114 pub visit_frequency: f64,
116 pub avg_session_duration: f64,
118 pub avg_products_viewed: f64,
120 pub cart_abandonment_rate: f64,
122 pub return_visit_rate: f64,
124 pub referral_rate: f64,
126}
127
128#[derive(Debug, Clone, Serialize, Deserialize)]
130pub struct ProductRecommendation {
131 pub product_id: String,
133 pub score: f64,
135 pub reason: RecommendationReason,
137 pub confidence: f64,
139 pub expected_revenue: f64,
141}
142
143#[derive(Debug, Clone, Serialize, Deserialize)]
145pub enum RecommendationReason {
146 SimilarProducts,
147 CustomersBought,
148 PopularInCategory,
149 PersonalizedPreference,
150 TrendingNow,
151 SeasonalRecommendation,
152}