1macro_rules! open_enum {
7 (
8 $(#[$meta:meta])*
9 pub enum $name:ident {
10 $( $(#[$vmeta:meta])* $variant:ident => $konst:ident = $value:literal, )*
11 }
12 $( subsets { $( $(#[$smeta:meta])* $sname:ident = [ $($sv:ident),* ]; )* } )?
13 ) => {
14 $(#[$meta])*
15 #[derive(Clone, serde::Serialize, serde::Deserialize)]
16 #[serde(from = "String", into = "String")]
17 #[non_exhaustive]
18 pub enum $name {
19 $( $(#[$vmeta])* #[doc = concat!("`", $value, "`")] $variant, )*
20 Other(String),
22 }
23
24 #[allow(missing_docs)]
25 impl $name {
26 $( pub const $konst: &'static str = $value; )*
27 pub const ALL: &'static [&'static str] = &[ $( $value ),* ];
29 $( $( $(#[$smeta])* pub const $sname: &'static [&'static str] = &[ $( Self::$sv ),* ]; )* )?
30
31 pub fn as_str(&self) -> &str {
33 match self {
34 $( Self::$variant => $value, )*
35 Self::Other(value) => value.as_str(),
36 }
37 }
38
39 pub fn is_known(&self) -> bool {
41 !matches!(self, Self::Other(_))
42 }
43 }
44
45 impl From<&str> for $name {
46 fn from(value: &str) -> Self {
47 match value {
48 $( $value => Self::$variant, )*
49 other => Self::Other(other.to_owned()),
50 }
51 }
52 }
53
54 impl From<String> for $name {
55 fn from(value: String) -> Self {
56 match value.as_str() {
57 $( $value => Self::$variant, )*
58 _ => Self::Other(value),
59 }
60 }
61 }
62
63 impl From<&String> for $name {
64 fn from(value: &String) -> Self {
65 Self::from(value.as_str())
66 }
67 }
68
69 impl From<$name> for String {
70 #[allow(unreachable_patterns)]
71 fn from(value: $name) -> Self {
72 match value {
73 $name::Other(value) => value,
74 known => known.as_str().to_owned(),
75 }
76 }
77 }
78
79 impl AsRef<str> for $name {
80 fn as_ref(&self) -> &str {
81 self.as_str()
82 }
83 }
84
85 impl std::fmt::Display for $name {
86 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
87 f.write_str(self.as_str())
88 }
89 }
90
91 impl std::fmt::Debug for $name {
92 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
93 write!(f, "{}({:?})", stringify!($name), self.as_str())
94 }
95 }
96
97 impl PartialEq for $name {
98 fn eq(&self, other: &Self) -> bool {
99 self.as_str() == other.as_str()
100 }
101 }
102
103 impl Eq for $name {}
104
105 impl std::hash::Hash for $name {
106 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
107 self.as_str().hash(state);
108 }
109 }
110
111 impl PartialEq<str> for $name {
112 fn eq(&self, other: &str) -> bool {
113 self.as_str() == other
114 }
115 }
116
117 impl PartialEq<&str> for $name {
118 fn eq(&self, other: &&str) -> bool {
119 self.as_str() == *other
120 }
121 }
122
123 impl PartialEq<$name> for &str {
124 fn eq(&self, other: &$name) -> bool {
125 *self == other.as_str()
126 }
127 }
128 };
129}
130
131open_enum! {
132 pub enum IncludeBlock {
134 Content => CONTENT = "content",
135 Companies => COMPANIES = "companies",
136 Events => EVENTS = "events",
137 }
138}
139
140open_enum! {
141 pub enum OrderBy {
143 PublishedAt => PUBLISHED_AT = "publishedAt",
144 FirstSeenAt => FIRST_SEEN_AT = "firstSeenAt",
145 RevisedAt => REVISED_AT = "revisedAt",
146 AvailableAt => AVAILABLE_AT = "availableAt",
147 }
148}
149
150open_enum! {
151 pub enum SortOrder {
153 Asc => ASC = "asc",
154 Desc => DESC = "desc",
155 }
156}
157
158open_enum! {
159 pub enum CompanyRole {
161 Acquirer => ACQUIRER = "acquirer",
162 Target => TARGET = "target",
163 Seller => SELLER = "seller",
164 Defendant => DEFENDANT = "defendant",
165 Subject => SUBJECT = "subject",
166 Counterparty => COUNTERPARTY = "counterparty",
167 Supplier => SUPPLIER = "supplier",
168 Customer => CUSTOMER = "customer",
169 Competitor => COMPETITOR = "competitor",
170 Mentioned => MENTIONED = "mentioned",
171 }
172}
173
174open_enum! {
175 pub enum EventType {
177 Earnings => EARNINGS = "earnings",
178 Guidance => GUIDANCE = "guidance",
179 Mna => MNA = "mna",
180 IpoListing => IPO_LISTING = "ipo_listing",
181 CapitalAction => CAPITAL_ACTION = "capital_action",
182 RatingAction => RATING_ACTION = "rating_action",
183 ManagementChange => MANAGEMENT_CHANGE = "management_change",
184 Legal => LEGAL = "legal",
185 Regulatory => REGULATORY = "regulatory",
186 BankruptcyDistress => BANKRUPTCY_DISTRESS = "bankruptcy_distress",
187 ProductPartnership => PRODUCT_PARTNERSHIP = "product_partnership",
188 InvestmentExpansion => INVESTMENT_EXPANSION = "investment_expansion",
189 OperationalIncident => OPERATIONAL_INCIDENT = "operational_incident",
190 LaborRestructuring => LABOR_RESTRUCTURING = "labor_restructuring",
191 Macro => MACRO = "macro",
192 Geopolitics => GEOPOLITICS = "geopolitics",
193 }
194}
195
196open_enum! {
197 pub enum EventDirection {
199 Positive => POSITIVE = "positive",
200 Negative => NEGATIVE = "negative",
201 Neutral => NEUTRAL = "neutral",
202 Unclear => UNCLEAR = "unclear",
203 }
204}
205
206open_enum! {
207 pub enum Importance {
209 Low => LOW = "low",
210 Medium => MEDIUM = "medium",
211 High => HIGH = "high",
212 Critical => CRITICAL = "critical",
213 }
214}
215
216impl Importance {
217 pub fn rank(&self) -> Option<usize> {
219 Self::ALL.iter().position(|v| *v == self.as_str())
220 }
221}
222
223open_enum! {
224 pub enum SentimentLabel {
226 Positive => POSITIVE = "positive",
227 Negative => NEGATIVE = "negative",
228 Neutral => NEUTRAL = "neutral",
229 }
230}
231
232open_enum! {
233 pub enum SourceType {
236 Newswire => NEWSWIRE = "newswire",
237 PressRelease => PRESS_RELEASE = "press_release",
238 FinancialMedia => FINANCIAL_MEDIA = "financial_media",
239 GeneralMedia => GENERAL_MEDIA = "general_media",
240 Aggregator => AGGREGATOR = "aggregator",
241 Blog => BLOG = "blog",
242 Government => GOVERNMENT = "government",
243 }
244}
245
246open_enum! {
247 pub enum StreamEventName {
249 ArticleCreated => ARTICLE_CREATED = "article.created",
250 ArticleUpdated => ARTICLE_UPDATED = "article.updated",
251 ConnectionAdmitted => CONNECTION_ADMITTED = "connection.admitted",
252 ConnectionPong => CONNECTION_PONG = "connection.pong",
253 ConnectionPreempted => CONNECTION_PREEMPTED = "connection.preempted",
254 ConnectionError => CONNECTION_ERROR = "connection.error",
255 }
256 subsets {
257 ARTICLE_EVENTS = [ARTICLE_CREATED, ARTICLE_UPDATED];
259 CONNECTION_EVENTS = [CONNECTION_ADMITTED, CONNECTION_PONG, CONNECTION_PREEMPTED, CONNECTION_ERROR];
261 }
262}
263
264open_enum! {
265 pub enum ConnectionErrorCode {
267 PingOnDefaultRoute => PING_ON_DEFAULT_ROUTE = "PING_ON_DEFAULT_ROUTE",
268 HandshakeFailed => HANDSHAKE_FAILED = "HANDSHAKE_FAILED",
269 ValidationFailed => VALIDATION_FAILED = "VALIDATION_FAILED",
270 SearchFailed => SEARCH_FAILED = "SEARCH_FAILED",
271 InternalError => INTERNAL_ERROR = "INTERNAL_ERROR",
272 }
273}
274
275open_enum! {
276 pub enum PreemptReason {
278 ConnectionLimit => CONNECTION_LIMIT = "connection_limit",
279 QuotaExceeded => QUOTA_EXCEEDED = "quota_exceeded",
280 }
281}
282
283open_enum! {
284 pub enum WebhookEventName {
286 ArticleCreated => ARTICLE_CREATED = "article.created",
287 ArticleUpdated => ARTICLE_UPDATED = "article.updated",
288 }
289}
290
291open_enum! {
292 pub enum ProblemCode {
294 ValidationFailed => VALIDATION_FAILED = "VALIDATION_FAILED",
295 CursorInvalid => CURSOR_INVALID = "CURSOR_INVALID",
296 CursorMismatch => CURSOR_MISMATCH = "CURSOR_MISMATCH",
297 Unauthorized => UNAUTHORIZED = "UNAUTHORIZED",
298 Forbidden => FORBIDDEN = "FORBIDDEN",
299 NotFound => NOT_FOUND = "NOT_FOUND",
300 RateLimited => RATE_LIMITED = "RATE_LIMITED",
301 InternalError => INTERNAL_ERROR = "INTERNAL_ERROR",
302 }
303}
304
305open_enum! {
306 pub enum RateLimitType {
308 Monthly => MONTHLY = "monthly",
309 Burst => BURST = "burst",
310 Unknown => UNKNOWN = "unknown",
311 }
312}
313
314open_enum! {
315 pub enum ReconnectReason {
317 Rotation => ROTATION = "rotation",
318 Watchdog => WATCHDOG = "watchdog",
319 Closed => CLOSED = "closed",
320 HandshakeFailed => HANDSHAKE_FAILED = "handshake_failed",
321 SearchFailed => SEARCH_FAILED = "search_failed",
322 DialFailed => DIAL_FAILED = "dial_failed",
323 DialRefused => DIAL_REFUSED = "dial_refused",
324 ConnectionLimit => CONNECTION_LIMIT = "connection_limit",
325 RateLimited => RATE_LIMITED = "rate_limited",
326 QuotaExceeded => QUOTA_EXCEEDED = "quota_exceeded",
327 }
328}