forked from Lead-Studios/veritix-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes_custom.py
More file actions
275 lines (206 loc) · 9.18 KB
/
types_custom.py
File metadata and controls
275 lines (206 loc) · 9.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
from datetime import date, datetime
from typing import Any, Dict, List, Literal, Optional
from pydantic import BaseModel, ConfigDict, Field, field_validator
# --- Fraud Detection Types ---
class FraudCheckRequest(BaseModel):
"""Request body for /check-fraud endpoint.
Contains a list of ticket purchase and transfer events to check for suspicious activity.
"""
model_config = ConfigDict(extra="forbid")
events: List[Dict[str, Any]] = Field(
..., description="List of event dicts. Each event should include at least: type (purchase|transfer), user, ip, ticket_id, timestamp (ISO8601 string)."
)
class FraudCheckResponse(BaseModel):
model_config = ConfigDict(extra="forbid")
triggered_rules: List[str] = Field(
..., description="List of fraud rule names triggered by the submitted events."
)
class PredictRequest(BaseModel):
"""Request body for /predict-scalper endpoint.
Each record represents aggregated event signals for a buyer/session.
"""
model_config = ConfigDict(extra="forbid")
features: List[float] = Field(
..., description="Feature vector: e.g., [tickets_per_txn, txns_per_min, avg_price_ratio, account_age_days, zip_mismatch, device_changes]"
)
@field_validator("features")
@classmethod
def validate_feature_length(cls, value: List[float]) -> List[float]:
if len(value) != 6:
raise ValueError("features must contain exactly 6 values")
return value
class PredictResponse(BaseModel):
model_config = ConfigDict(extra="forbid")
probability: float
class TicketRequest(BaseModel):
model_config = ConfigDict(extra="forbid")
ticket_id: str = Field(..., pattern=r"^[A-Za-z0-9_-]+$", description="Alphanumeric ticket identifier")
event: str = Field(..., min_length=1, description="Event name")
user: str = Field(..., min_length=1, description="User identifier or email")
class QRResponse(BaseModel):
model_config = ConfigDict(extra="forbid")
qr_base64: str
token: str
class QRValidateRequest(BaseModel):
model_config = ConfigDict(extra="forbid")
qr_text: str = Field(..., description="Decoded text content from the QR code (JSON)")
class QRValidateResponse(BaseModel):
model_config = ConfigDict(extra="forbid")
isValid: bool
metadata: Optional[Dict[str, Any]] = None
# --- Search Events Types ---
class SearchEventsRequest(BaseModel):
"""Request body for /search-events endpoint.
Contains a natural language query to search for events and optional
price/capacity filters that override NLP-inferred values.
"""
model_config = ConfigDict(extra="forbid")
query: str = Field(
...,
min_length=1,
description="Natural language search query (e.g., 'music events in Lagos this weekend')",
)
min_price: Optional[float] = Field(
None, ge=0, description="Minimum ticket price filter (inclusive)"
)
max_price: Optional[float] = Field(
None, ge=0, description="Maximum ticket price filter (inclusive)"
)
max_capacity: Optional[int] = Field(
None, ge=1, description="Maximum venue capacity filter (inclusive)"
)
class EventResult(BaseModel):
"""Represents a single event in search results."""
model_config = ConfigDict(extra="forbid")
id: str = Field(..., description="Unique event identifier")
name: str = Field(..., description="Event name")
description: str = Field(..., description="Event description")
event_type: str = Field(..., description="Event category/type")
location: str = Field(..., description="Event location")
date: str = Field(..., description="Event date in ISO format")
price: float = Field(..., description="Ticket price")
capacity: int = Field(..., description="Venue capacity")
class SearchEventsResponse(BaseModel):
"""Response body for /search-events endpoint."""
model_config = ConfigDict(extra="forbid")
query: str = Field(..., description="The original search query")
results: List[EventResult] = Field(..., description="List of matching events")
count: int = Field(..., description="Number of results found")
keywords_extracted: Dict[str, Any] = Field(..., description="Keywords extracted from the query")
class DailyReportRequest(BaseModel):
"""Request body for /generate-daily-report endpoint."""
model_config = ConfigDict(extra="forbid")
target_date: Optional[date] = Field(None, description="Target date in YYYY-MM-DD format. Defaults to today.")
output_format: Literal["csv", "json"] = Field("csv", description="Output format: 'csv' or 'json'")
event_id: Optional[str] = Field(None, description="Optional event ID to scope the report. Null means all events.")
force_regenerate: bool = Field(False, description="When True, skip cache and always generate a fresh report.")
class DailyReportResponse(BaseModel):
"""Response body for /generate-daily-report endpoint."""
model_config = ConfigDict(extra="forbid")
success: bool = Field(..., description="Whether report generation succeeded")
report_path: Optional[str] = Field(None, description="Path to generated report file")
report_date: str = Field(..., description="Date of the report")
summary: Dict[str, Any] = Field(..., description="Summary statistics")
cache_hit: bool = Field(False, description="True when the response was served from a cached report")
message: Optional[str] = Field(None, description="Additional information or error message")
class RecommendRequest(BaseModel):
model_config = ConfigDict(extra="forbid")
user_id: str = Field(..., min_length=1)
class RecommendResponse(BaseModel):
model_config = ConfigDict(extra="forbid")
recommendations: List[str]
class ChatMessageSendRequest(BaseModel):
model_config = ConfigDict(extra="forbid")
sender_id: str = Field(..., min_length=1)
sender_type: str = Field(..., min_length=1)
content: str = Field(..., min_length=1)
metadata: Dict[str, Any] = Field(default_factory=dict)
class ChatMessageSendResponse(BaseModel):
model_config = ConfigDict(extra="forbid")
status: Literal["success"]
message_id: str
class ChatMessageItem(BaseModel):
model_config = ConfigDict(extra="forbid")
id: str
sender_id: str
sender_type: str
content: str
timestamp: datetime
conversation_id: str
metadata: Optional[Dict[str, Any]] = None
class ChatMessageHistoryQuery(BaseModel):
model_config = ConfigDict(extra="forbid")
limit: int = Field(50, ge=1, le=500)
class ChatMessageHistoryResponse(BaseModel):
model_config = ConfigDict(extra="forbid")
conversation_id: str
messages: List[ChatMessageItem]
count: int
class ChatEscalateRequest(BaseModel):
model_config = ConfigDict(extra="forbid")
reason: str = Field("user_request", min_length=1)
metadata: Dict[str, Any] = Field(default_factory=dict)
class ChatEscalateResponse(BaseModel):
model_config = ConfigDict(extra="forbid")
status: Literal["success"]
escalation_id: str
reason: str
timestamp: str
class EscalationItem(BaseModel):
model_config = ConfigDict(extra="forbid")
id: str
conversation_id: str
reason: str
timestamp: datetime
metadata: Optional[Dict[str, Any]] = None
class ChatEscalationsResponse(BaseModel):
model_config = ConfigDict(extra="forbid")
conversation_id: str
escalations: List[EscalationItem]
count: int
class ChatUserConversationsResponse(BaseModel):
model_config = ConfigDict(extra="forbid")
user_id: str
conversations: List[str]
count: int
class AnalyticsStatsQuery(BaseModel):
model_config = ConfigDict(extra="forbid")
event_id: Optional[str] = None
class AnalyticsListQuery(BaseModel):
model_config = ConfigDict(extra="forbid")
event_id: str = Field(..., min_length=1)
limit: int = Field(50, ge=1, le=500)
class AnalyticsScansResponse(BaseModel):
model_config = ConfigDict(extra="forbid")
event_id: str
scans: List[Dict[str, Any]]
count: int
class AnalyticsTransfersResponse(BaseModel):
model_config = ConfigDict(extra="forbid")
event_id: str
transfers: List[Dict[str, Any]]
count: int
class AnalyticsInvalidAttemptsResponse(BaseModel):
model_config = ConfigDict(extra="forbid")
event_id: str
attempts: List[Dict[str, Any]]
count: int
class RootResponse(BaseModel):
model_config = ConfigDict(extra="forbid")
message: str
class HealthResponse(BaseModel):
model_config = ConfigDict(extra="forbid")
status: str
service: str
api_version: str
class ReportItem(BaseModel):
model_config = ConfigDict(extra="forbid")
filename: str = Field(..., description="Report filename")
report_date: str = Field(..., description="Date the report covers (YYYY-MM-DD)")
format: str = Field(..., description="File format: csv or json")
size_bytes: int = Field(..., description="File size in bytes")
generated_at: str = Field(..., description="ISO timestamp when the report was generated")
download_url: str = Field(..., description="Relative URL to download the report")
class ReportsListResponse(BaseModel):
model_config = ConfigDict(extra="forbid")
reports: List[ReportItem] = Field(..., description="List of generated reports (up to 100)")