Skip to main content

systemprompt_content/models/builders/
link.rs

1use chrono::{DateTime, Utc};
2use systemprompt_identifiers::{
3    CampaignId, ContentId, ContextId, LinkClickId, LinkId, SessionId, TaskId, UserId,
4};
5
6#[derive(Debug, Clone)]
7pub struct CreateLinkParams {
8    pub short_code: String,
9    pub target_url: String,
10    pub link_type: String,
11    pub source_content_id: Option<ContentId>,
12    pub source_page: Option<String>,
13    pub campaign_id: Option<CampaignId>,
14    pub campaign_name: Option<String>,
15    pub utm_params: Option<String>,
16    pub link_text: Option<String>,
17    pub link_position: Option<String>,
18    pub destination_type: Option<String>,
19    pub is_active: bool,
20    pub expires_at: Option<DateTime<Utc>>,
21}
22
23impl CreateLinkParams {
24    pub const fn new(short_code: String, target_url: String, link_type: String) -> Self {
25        Self {
26            short_code,
27            target_url,
28            link_type,
29            source_content_id: None,
30            source_page: None,
31            campaign_id: None,
32            campaign_name: None,
33            utm_params: None,
34            link_text: None,
35            link_position: None,
36            destination_type: None,
37            is_active: true,
38            expires_at: None,
39        }
40    }
41
42    pub fn with_source_content_id(mut self, source_content_id: Option<ContentId>) -> Self {
43        self.source_content_id = source_content_id;
44        self
45    }
46
47    pub fn with_source_page(mut self, source_page: Option<String>) -> Self {
48        self.source_page = source_page;
49        self
50    }
51
52    pub fn with_campaign_id(mut self, campaign_id: Option<CampaignId>) -> Self {
53        self.campaign_id = campaign_id;
54        self
55    }
56
57    pub fn with_campaign_name(mut self, campaign_name: Option<String>) -> Self {
58        self.campaign_name = campaign_name;
59        self
60    }
61
62    pub fn with_utm_params(mut self, utm_params: Option<String>) -> Self {
63        self.utm_params = utm_params;
64        self
65    }
66
67    pub fn with_link_text(mut self, link_text: Option<String>) -> Self {
68        self.link_text = link_text;
69        self
70    }
71
72    pub fn with_link_position(mut self, link_position: Option<String>) -> Self {
73        self.link_position = link_position;
74        self
75    }
76
77    pub fn with_destination_type(mut self, destination_type: Option<String>) -> Self {
78        self.destination_type = destination_type;
79        self
80    }
81
82    pub const fn with_is_active(mut self, is_active: bool) -> Self {
83        self.is_active = is_active;
84        self
85    }
86
87    pub const fn with_expires_at(mut self, expires_at: Option<DateTime<Utc>>) -> Self {
88        self.expires_at = expires_at;
89        self
90    }
91}
92
93#[derive(Debug, Clone)]
94pub struct RecordClickParams {
95    pub click_id: LinkClickId,
96    pub link_id: LinkId,
97    pub session_id: SessionId,
98    pub user_id: Option<UserId>,
99    pub context_id: Option<ContextId>,
100    pub task_id: Option<TaskId>,
101    pub referrer_page: Option<String>,
102    pub referrer_url: Option<String>,
103    pub clicked_at: DateTime<Utc>,
104    pub user_agent: Option<String>,
105    pub ip_address: Option<String>,
106    pub device_type: Option<String>,
107    pub country: Option<String>,
108    pub is_first_click: bool,
109    pub is_conversion: bool,
110}
111
112impl RecordClickParams {
113    pub const fn new(
114        click_id: LinkClickId,
115        link_id: LinkId,
116        session_id: SessionId,
117        clicked_at: DateTime<Utc>,
118    ) -> Self {
119        Self {
120            click_id,
121            link_id,
122            session_id,
123            user_id: None,
124            context_id: None,
125            task_id: None,
126            referrer_page: None,
127            referrer_url: None,
128            clicked_at,
129            user_agent: None,
130            ip_address: None,
131            device_type: None,
132            country: None,
133            is_first_click: false,
134            is_conversion: false,
135        }
136    }
137
138    pub fn with_user_id(mut self, user_id: Option<UserId>) -> Self {
139        self.user_id = user_id;
140        self
141    }
142
143    pub fn with_context_id(mut self, context_id: Option<ContextId>) -> Self {
144        self.context_id = context_id;
145        self
146    }
147
148    pub fn with_task_id(mut self, task_id: Option<TaskId>) -> Self {
149        self.task_id = task_id;
150        self
151    }
152
153    pub fn with_referrer_page(mut self, referrer_page: Option<String>) -> Self {
154        self.referrer_page = referrer_page;
155        self
156    }
157
158    pub fn with_referrer_url(mut self, referrer_url: Option<String>) -> Self {
159        self.referrer_url = referrer_url;
160        self
161    }
162
163    pub fn with_user_agent(mut self, user_agent: Option<String>) -> Self {
164        self.user_agent = user_agent;
165        self
166    }
167
168    pub fn with_ip_address(mut self, ip_address: Option<String>) -> Self {
169        self.ip_address = ip_address;
170        self
171    }
172
173    pub fn with_device_type(mut self, device_type: Option<String>) -> Self {
174        self.device_type = device_type;
175        self
176    }
177
178    pub fn with_country(mut self, country: Option<String>) -> Self {
179        self.country = country;
180        self
181    }
182
183    pub const fn with_is_first_click(mut self, is_first_click: bool) -> Self {
184        self.is_first_click = is_first_click;
185        self
186    }
187
188    pub const fn with_is_conversion(mut self, is_conversion: bool) -> Self {
189        self.is_conversion = is_conversion;
190        self
191    }
192}
193
194#[derive(Debug, Clone)]
195pub struct TrackClickParams {
196    pub link_id: LinkId,
197    pub session_id: SessionId,
198    pub user_id: Option<UserId>,
199    pub context_id: Option<ContextId>,
200    pub task_id: Option<TaskId>,
201    pub referrer_page: Option<String>,
202    pub referrer_url: Option<String>,
203    pub user_agent: Option<String>,
204    pub ip_address: Option<String>,
205    pub device_type: Option<String>,
206    pub country: Option<String>,
207}
208
209impl TrackClickParams {
210    pub const fn new(link_id: LinkId, session_id: SessionId) -> Self {
211        Self {
212            link_id,
213            session_id,
214            user_id: None,
215            context_id: None,
216            task_id: None,
217            referrer_page: None,
218            referrer_url: None,
219            user_agent: None,
220            ip_address: None,
221            device_type: None,
222            country: None,
223        }
224    }
225
226    pub fn with_user_id(mut self, user_id: Option<UserId>) -> Self {
227        self.user_id = user_id;
228        self
229    }
230
231    pub fn with_context_id(mut self, context_id: Option<ContextId>) -> Self {
232        self.context_id = context_id;
233        self
234    }
235
236    pub fn with_task_id(mut self, task_id: Option<TaskId>) -> Self {
237        self.task_id = task_id;
238        self
239    }
240
241    pub fn with_referrer_page(mut self, referrer_page: Option<String>) -> Self {
242        self.referrer_page = referrer_page;
243        self
244    }
245
246    pub fn with_referrer_url(mut self, referrer_url: Option<String>) -> Self {
247        self.referrer_url = referrer_url;
248        self
249    }
250
251    pub fn with_user_agent(mut self, user_agent: Option<String>) -> Self {
252        self.user_agent = user_agent;
253        self
254    }
255
256    pub fn with_ip_address(mut self, ip_address: Option<String>) -> Self {
257        self.ip_address = ip_address;
258        self
259    }
260
261    pub fn with_device_type(mut self, device_type: Option<String>) -> Self {
262        self.device_type = device_type;
263        self
264    }
265
266    pub fn with_country(mut self, country: Option<String>) -> Self {
267        self.country = country;
268        self
269    }
270}