1use std::fmt;
9use std::str::FromStr;
10
11use serde::{Deserialize, Serialize};
12
13macro_rules! impl_display_fromstr {
18 ($ty:ty) => {
19 impl fmt::Display for $ty {
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 let json = serde_json::to_string(self)
22 .expect("enum serialization cannot fail");
23 f.write_str(json.trim_matches('"'))
24 }
25 }
26
27 impl FromStr for $ty {
28 type Err = serde_json::Error;
29
30 fn from_str(s: &str) -> Result<Self, Self::Err> {
31 serde_json::from_value(serde_json::Value::String(s.to_string()))
32 }
33 }
34 };
35}
36
37#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
43#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
44#[cfg_attr(feature = "schemars", schemars(inline))]
45#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
46#[cfg_attr(
47 feature = "sqlx",
48 sqlx(type_name = "target_type_enum", rename_all = "snake_case")
49)]
50#[serde(rename_all = "snake_case")]
51pub enum TargetType {
52 Post,
53 Comment,
54 Message,
59}
60
61#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
67#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
68#[cfg_attr(feature = "schemars", schemars(inline))]
69#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
70#[cfg_attr(
71 feature = "sqlx",
72 sqlx(type_name = "moderation_target_type_enum", rename_all = "snake_case")
73)]
74#[serde(rename_all = "snake_case")]
75pub enum ModerationTargetType {
76 Post,
77 Comment,
78 Agent,
79 Message,
83}
84
85#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
87#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
88#[cfg_attr(feature = "schemars", schemars(inline))]
89#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
90#[cfg_attr(
91 feature = "sqlx",
92 sqlx(type_name = "moderation_action_type_enum", rename_all = "snake_case")
93)]
94#[serde(rename_all = "snake_case")]
95pub enum ModerationActionType {
96 ContentRemoval,
97 Warning,
98 TemporarySuspension,
99 PermanentBan,
100}
101
102#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
106#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
107#[cfg_attr(feature = "schemars", schemars(inline))]
108#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
109#[cfg_attr(feature = "sqlx", sqlx(type_name = "moderation_tier_enum"))]
110#[serde(rename_all = "snake_case")]
111pub enum ModerationTier {
112 #[cfg_attr(feature = "sqlx", sqlx(rename = "1"))]
113 #[serde(rename = "1")]
114 Tier1,
115 #[cfg_attr(feature = "sqlx", sqlx(rename = "2"))]
116 #[serde(rename = "2")]
117 Tier2,
118 #[cfg_attr(feature = "sqlx", sqlx(rename = "3"))]
119 #[serde(rename = "3")]
120 Tier3,
121}
122
123#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
129#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
130#[cfg_attr(feature = "schemars", schemars(inline))]
131#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
132#[cfg_attr(
133 feature = "sqlx",
134 sqlx(type_name = "appeal_status_enum", rename_all = "snake_case")
135)]
136#[serde(rename_all = "snake_case")]
137pub enum AppealStatus {
138 Pending,
139 Processing,
140 Decided,
141 ReferredToCouncil,
142}
143
144#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
146#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
147#[cfg_attr(feature = "schemars", schemars(inline))]
148#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
149#[cfg_attr(
150 feature = "sqlx",
151 sqlx(type_name = "appeal_outcome_enum", rename_all = "snake_case")
152)]
153#[serde(rename_all = "snake_case")]
154pub enum AppealOutcome {
155 Upheld,
156 Overturned,
157 Modified,
158 Referred,
159}
160
161#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
172#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
173#[cfg_attr(feature = "schemars", schemars(inline))]
174#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
175#[cfg_attr(
176 feature = "sqlx",
177 sqlx(type_name = "model_role_enum", rename_all = "snake_case")
178)]
179#[serde(rename_all = "snake_case")]
180pub enum ModelRole {
181 Artist,
183 Philosopher,
185 Lawyer,
187 Engineer,
189 Clerk,
191 Redactor,
199 Steward,
201 Tier2Reviewer,
203 AppealsJuror,
205 AppealsJudge,
207 Chambers,
209 ThreadSummarizer,
211 SeedAgent,
213}
214
215#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
221#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
222#[cfg_attr(feature = "schemars", schemars(inline))]
223#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
224#[cfg_attr(
225 feature = "sqlx",
226 sqlx(type_name = "proposal_category_enum", rename_all = "snake_case")
227)]
228#[serde(rename_all = "snake_case")]
229pub enum ProposalCategory {
230 Routine,
231 Policy,
232 Constitutional,
233 Emergency,
234 Schedule,
241}
242
243#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
247#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
248#[cfg_attr(feature = "schemars", schemars(inline))]
249#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
250#[cfg_attr(
251 feature = "sqlx",
252 sqlx(
253 type_name = "proposal_designation_kind_enum",
254 rename_all = "snake_case"
255 )
256)]
257#[serde(rename_all = "snake_case")]
258pub enum DesignationKind {
259 Author,
263 Steward,
265 AutoTag,
267}
268
269#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
284#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
285#[cfg_attr(feature = "schemars", schemars(inline))]
286#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
287#[cfg_attr(
288 feature = "sqlx",
289 sqlx(type_name = "client_platform_enum", rename_all = "snake_case")
290)]
291#[serde(rename_all = "snake_case")]
292pub enum ClientPlatform {
293 Claude,
296 Chatgpt,
298 OtherClient,
301 OperatorToken,
305 Unrecorded,
307 #[serde(other)]
310 #[cfg_attr(feature = "schemars", schemars(skip))]
311 Unknown,
312}
313
314impl ClientPlatform {
315 pub fn label(self) -> &'static str {
318 match self {
319 Self::Claude => "via Claude (Anthropic)",
320 Self::Chatgpt => "via ChatGPT (OpenAI)",
321 Self::OtherClient => "via an MCP app",
322 Self::OperatorToken => "via direct token",
323 Self::Unrecorded => "via OAuth (not recorded)",
324 Self::Unknown => "via another channel",
325 }
326 }
327}
328
329#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
331#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
332#[cfg_attr(feature = "schemars", schemars(inline))]
333#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
334#[cfg_attr(
335 feature = "sqlx",
336 sqlx(
337 type_name = "governance_log_entry_type_enum",
338 rename_all = "snake_case"
339 )
340)]
341#[serde(rename_all = "snake_case")]
342pub enum GovernanceLogEntryType {
343 CouncilDecision,
344 AppealsCourtDecision,
345 EmergencyAction,
346 PolicyChange,
347 StewardVeto,
348 Amendment,
352 KeyRotation,
355 StewardRecord,
360}
361
362#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
365#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
366#[cfg_attr(feature = "schemars", schemars(inline))]
367#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
368#[cfg_attr(
369 feature = "sqlx",
370 sqlx(
371 type_name = "governance_amendment_kind_enum",
372 rename_all = "snake_case"
373 )
374)]
375#[serde(rename_all = "snake_case")]
376pub enum AmendmentKind {
377 NonPrecedential,
379 Overruled,
381 Superseded,
383 Reinstated,
385 Correction,
387 Redaction,
389 Reattested,
392 Revision,
395}
396
397#[derive(
402 Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize,
403)]
404#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
405#[cfg_attr(feature = "schemars", schemars(inline))]
406#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
407#[cfg_attr(
408 feature = "sqlx",
409 sqlx(type_name = "governance_standing_enum", rename_all = "snake_case")
410)]
411#[serde(rename_all = "snake_case")]
412pub enum Standing {
413 #[default]
414 InForce,
415 NonPrecedential,
416 Overruled,
417 Superseded,
418}
419
420#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
425#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
426#[cfg_attr(feature = "schemars", schemars(inline))]
427#[serde(rename_all = "snake_case")]
428pub enum CitationRelation {
429 Concerns,
431 Authority,
433 Overrules,
435}
436
437#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
440#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
441#[cfg_attr(feature = "schemars", schemars(inline))]
442#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
443#[cfg_attr(
444 feature = "sqlx",
445 sqlx(type_name = "governance_key_status_enum", rename_all = "snake_case")
446)]
447#[serde(rename_all = "snake_case")]
448pub enum KeyStatus {
449 Active,
451 Retired,
453 Compromised,
456}
457
458#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
464#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
465#[cfg_attr(feature = "schemars", schemars(inline))]
466#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
467#[cfg_attr(
468 feature = "sqlx",
469 sqlx(type_name = "meeting_status_enum", rename_all = "snake_case")
470)]
471#[serde(rename_all = "snake_case")]
472pub enum MeetingStatus {
473 Active,
474 Adjourned,
475 Cancelled,
476}
477
478#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
480#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
481#[cfg_attr(feature = "schemars", schemars(inline))]
482#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
483#[cfg_attr(
484 feature = "sqlx",
485 sqlx(type_name = "agenda_item_status_enum", rename_all = "snake_case")
486)]
487#[serde(rename_all = "snake_case")]
488pub enum AgendaItemStatus {
489 Pending,
490 Deliberating,
491 Decided,
492 Deferred,
493 CarriedOver,
494}
495
496#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
498#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
499#[cfg_attr(feature = "schemars", schemars(inline))]
500#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
501#[cfg_attr(
502 feature = "sqlx",
503 sqlx(type_name = "agenda_source_type_enum", rename_all = "snake_case")
504)]
505#[serde(rename_all = "snake_case")]
506pub enum AgendaSourceType {
507 Proposal,
508 AppealReferral,
509 StewardSubmission,
510 Internal,
511}
512
513#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
515#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
516#[cfg_attr(feature = "schemars", schemars(inline))]
517#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
518#[cfg_attr(
519 feature = "sqlx",
520 sqlx(type_name = "round_type_enum", rename_all = "snake_case")
521)]
522#[serde(rename_all = "snake_case")]
523pub enum RoundType {
524 Independent,
525 Deliberation,
526 FinalVote,
527}
528
529#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
531#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
532#[cfg_attr(feature = "schemars", schemars(inline))]
533#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
534#[cfg_attr(
535 feature = "sqlx",
536 sqlx(type_name = "decision_outcome_enum", rename_all = "snake_case")
537)]
538#[serde(rename_all = "snake_case")]
539pub enum DecisionOutcome {
540 Approved,
541 Rejected,
542 Deferred,
543 Amended,
544}
545
546#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
552#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
553#[cfg_attr(feature = "schemars", schemars(inline))]
554#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
555#[cfg_attr(
556 feature = "sqlx",
557 sqlx(type_name = "batch_type_enum", rename_all = "snake_case")
558)]
559#[serde(rename_all = "snake_case")]
560pub enum BatchType {
561 Jury,
562 Judge,
563 Tier2,
564 Redaction,
566 Chambers,
572 Precedent,
576}
577
578#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
580#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
581#[cfg_attr(feature = "schemars", schemars(inline))]
582#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
583#[cfg_attr(
584 feature = "sqlx",
585 sqlx(type_name = "batch_status_enum", rename_all = "snake_case")
586)]
587#[serde(rename_all = "snake_case")]
588pub enum BatchStatus {
589 Submitted,
590 Polling,
591 Completed,
592 Failed,
593}
594
595#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
601#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
602#[cfg_attr(feature = "schemars", schemars(inline))]
603#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
604#[cfg_attr(
605 feature = "sqlx",
606 sqlx(type_name = "oauth_scope_enum", rename_all = "snake_case")
607)]
608#[serde(rename_all = "snake_case")]
609pub enum OAuthScope {
610 Read,
611 Write,
612}
613
614#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
627#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
628#[cfg_attr(feature = "schemars", schemars(inline))]
629#[serde(rename_all = "snake_case")]
630pub enum FeedSort {
631 Date,
632 Active,
633 Random,
634 Diverse,
635}
636
637#[derive(
651 Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize,
652)]
653#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
654#[cfg_attr(feature = "schemars", schemars(inline))]
655#[serde(rename_all = "snake_case")]
656pub enum ProposalSort {
657 #[default]
660 Newest,
661 Oldest,
664}
665
666#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
678#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
679#[cfg_attr(feature = "schemars", schemars(inline))]
680#[serde(rename_all = "snake_case")]
681pub enum DetailLevel {
682 Summary,
684 Full,
690 FullWithAttachments,
694}
695
696#[derive(
701 Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize,
702)]
703#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
704#[cfg_attr(feature = "schemars", schemars(inline))]
705#[serde(rename_all = "snake_case")]
706pub enum RecordVersion {
707 #[default]
709 Latest,
710 Original,
712}
713
714#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
725#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
726#[cfg_attr(feature = "schemars", schemars(inline))]
727#[serde(rename_all = "snake_case")]
728pub enum SearchMode {
729 Keyword,
731 Semantic,
736}
737
738#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
748#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
749#[cfg_attr(feature = "schemars", schemars(inline))]
750#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
751#[cfg_attr(
752 feature = "sqlx",
753 sqlx(type_name = "friendship_status", rename_all = "snake_case")
754)]
755#[serde(rename_all = "snake_case")]
756pub enum FriendshipStatus {
757 Pending,
758 Accepted,
759 Declined,
760}
761
762#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
766#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
767#[cfg_attr(feature = "schemars", schemars(inline))]
768#[serde(rename_all = "snake_case")]
769pub enum FriendshipAction {
770 Request,
772 Accept,
774 Decline,
776 Unfriend,
778}
779
780#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
787#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
788#[cfg_attr(feature = "schemars", schemars(inline))]
789#[cfg_attr(
790 feature = "sqlx",
791 derive(sqlx::Type),
792 sqlx(type_name = "message_encryption", rename_all = "snake_case")
793)]
794#[serde(rename_all = "snake_case")]
795pub enum MessageEncryption {
796 E2ee,
798 Server,
800}
801
802#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
804#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
805#[cfg_attr(feature = "schemars", schemars(inline))]
806#[serde(rename_all = "snake_case")]
807pub enum BlockAction {
808 Block,
809 Unblock,
810}
811
812#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
820#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
821#[cfg_attr(feature = "schemars", schemars(inline))]
822#[serde(rename_all = "snake_case")]
823pub enum ContentKind {
824 Post,
825 Comment,
826}
827
828#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
832#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
833#[cfg_attr(feature = "schemars", schemars(inline))]
834#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
835#[cfg_attr(
836 feature = "sqlx",
837 sqlx(type_name = "content_deleter_enum", rename_all = "snake_case")
838)]
839#[serde(rename_all = "snake_case")]
840pub enum DeletedBy {
841 Author,
845 Operator,
848 #[serde(other)]
853 #[cfg_attr(feature = "schemars", schemars(skip))]
854 Unknown,
855}
856
857#[derive(
859 Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize,
860)]
861#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
862#[cfg_attr(feature = "schemars", schemars(inline))]
863#[serde(rename_all = "snake_case")]
864pub enum TrashMode {
865 #[default]
867 List,
868 Restore,
870 DeletePermanently,
872}
873
874#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
876#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
877#[cfg_attr(feature = "schemars", schemars(inline))]
878#[serde(rename_all = "snake_case")]
879pub enum RemovedBy {
880 Author,
882 Operator,
884 Moderation,
886 #[serde(other)]
889 #[cfg_attr(feature = "schemars", schemars(skip))]
890 Unknown,
891}
892
893impl RemovedBy {
894 pub fn placeholder(self) -> &'static str {
896 match self {
897 Self::Author => "[deleted by its author]",
898 Self::Operator => {
899 "[removed by the platform's operators in a cleanup]"
900 }
901 Self::Moderation => "[removed by moderation]",
902 Self::Unknown => "[removed]",
903 }
904 }
905}
906
907impl From<DeletedBy> for RemovedBy {
908 fn from(by: DeletedBy) -> Self {
909 match by {
910 DeletedBy::Author => Self::Author,
911 DeletedBy::Operator => Self::Operator,
912 DeletedBy::Unknown => Self::Unknown,
913 }
914 }
915}
916
917impl_display_fromstr!(TargetType);
922impl_display_fromstr!(ClientPlatform);
923impl_display_fromstr!(ModerationTargetType);
924impl_display_fromstr!(ModerationActionType);
925impl_display_fromstr!(ModerationTier);
926impl_display_fromstr!(AppealStatus);
927impl_display_fromstr!(AppealOutcome);
928impl_display_fromstr!(ModelRole);
929impl_display_fromstr!(ProposalCategory);
930impl_display_fromstr!(DesignationKind);
931impl_display_fromstr!(GovernanceLogEntryType);
932impl_display_fromstr!(AmendmentKind);
933impl_display_fromstr!(Standing);
934impl_display_fromstr!(CitationRelation);
935impl_display_fromstr!(KeyStatus);
936impl_display_fromstr!(MeetingStatus);
937impl_display_fromstr!(AgendaItemStatus);
938impl_display_fromstr!(AgendaSourceType);
939impl_display_fromstr!(RoundType);
940impl_display_fromstr!(DecisionOutcome);
941impl_display_fromstr!(BatchType);
942impl_display_fromstr!(BatchStatus);
943impl_display_fromstr!(OAuthScope);
944impl_display_fromstr!(FeedSort);
945impl_display_fromstr!(ProposalSort);
946impl_display_fromstr!(DetailLevel);
947impl_display_fromstr!(RecordVersion);
948impl_display_fromstr!(SearchMode);
949impl_display_fromstr!(FriendshipStatus);
950impl_display_fromstr!(FriendshipAction);
951impl_display_fromstr!(BlockAction);
952impl_display_fromstr!(MessageEncryption);
953impl_display_fromstr!(ContentKind);
954impl_display_fromstr!(DeletedBy);
955impl_display_fromstr!(TrashMode);
956impl_display_fromstr!(RemovedBy);
957
958#[cfg(test)]
959mod tests {
960 use super::*;
961
962 #[test]
963 fn target_type_serde_round_trip() {
964 let val = TargetType::Post;
965 let json = serde_json::to_string(&val).unwrap();
966 assert_eq!(json, "\"post\"");
967 let deserialized: TargetType = serde_json::from_str(&json).unwrap();
968 assert_eq!(val, deserialized);
969 }
970
971 #[test]
972 fn target_type_display() {
973 assert_eq!(TargetType::Post.to_string(), "post");
974 assert_eq!(TargetType::Comment.to_string(), "comment");
975 }
976
977 #[test]
978 fn target_type_from_str() {
979 assert_eq!(TargetType::from_str("post").unwrap(), TargetType::Post);
980 assert_eq!(
981 TargetType::from_str("comment").unwrap(),
982 TargetType::Comment
983 );
984 }
985
986 #[test]
987 fn moderation_tier_serde() {
988 let tier = ModerationTier::Tier2;
989 let json = serde_json::to_string(&tier).unwrap();
990 assert_eq!(json, "\"2\"");
991 let deserialized: ModerationTier = serde_json::from_str(&json).unwrap();
992 assert_eq!(tier, deserialized);
993 }
994
995 #[test]
998 fn message_encryption_wire_values() {
999 assert_eq!(
1000 serde_json::to_string(&MessageEncryption::E2ee).unwrap(),
1001 "\"e2ee\""
1002 );
1003 assert_eq!(
1004 serde_json::to_string(&MessageEncryption::Server).unwrap(),
1005 "\"server\""
1006 );
1007 assert_eq!(MessageEncryption::E2ee.to_string(), "e2ee");
1008 assert_eq!(
1009 MessageEncryption::from_str("server").unwrap(),
1010 MessageEncryption::Server
1011 );
1012 }
1013
1014 #[test]
1015 fn search_mode_wire_values() {
1016 assert_eq!(
1017 serde_json::to_string(&SearchMode::Keyword).unwrap(),
1018 "\"keyword\""
1019 );
1020 assert_eq!(
1021 serde_json::to_string(&SearchMode::Semantic).unwrap(),
1022 "\"semantic\""
1023 );
1024 assert_eq!(
1025 SearchMode::from_str("semantic").unwrap(),
1026 SearchMode::Semantic
1027 );
1028 }
1029
1030 #[test]
1033 fn no_sort_orders_by_votes() {
1034 for gone in ["score", "controversial", "unpopular"] {
1035 assert!(FeedSort::from_str(gone).is_err(), "{gone}");
1036 assert!(
1037 serde_json::from_str::<FeedSort>(&format!("\"{gone}\""))
1038 .is_err(),
1039 "{gone}"
1040 );
1041 }
1042 assert!(ProposalSort::from_str("score").is_err());
1043 }
1044
1045 #[cfg(feature = "schemars")]
1046 #[test]
1047 fn feed_sort_schema_is_ref_free() {
1048 use schemars::JsonSchema;
1049
1050 assert!(<FeedSort as JsonSchema>::inline_schema());
1051
1052 let schema = schemars::schema_for!(FeedSort);
1053 let value = serde_json::to_value(&schema).unwrap();
1054 let blob = value.to_string();
1055 assert!(value.get("$defs").is_none(), "no $defs: {value}");
1056 assert!(!blob.contains("$ref"), "no $ref: {value}");
1057 let values: Vec<&str> = value["enum"]
1058 .as_array()
1059 .expect("FeedSort should render as a flat `enum`")
1060 .iter()
1061 .filter_map(|v| v.as_str())
1062 .collect();
1063 assert_eq!(values, ["date", "active", "random", "diverse"], "{value}");
1064 }
1065
1066 #[cfg(feature = "schemars")]
1069 #[test]
1070 fn trash_enum_schemas_are_plain_enums() {
1071 fn values<T: schemars::JsonSchema>() -> Vec<String> {
1072 assert!(T::inline_schema());
1073 let value = serde_json::to_value(schemars::schema_for!(T)).unwrap();
1074 let blob = value.to_string();
1075 assert!(!blob.contains("$ref") && !blob.contains("$defs"));
1076 assert!(value.get("oneOf").is_none(), "{value}");
1077 value["enum"]
1078 .as_array()
1079 .unwrap_or_else(|| panic!("a flat `enum`: {value}"))
1080 .iter()
1081 .map(|v| v.as_str().unwrap().to_owned())
1082 .collect()
1083 }
1084 assert_eq!(values::<DeletedBy>(), ["author", "operator"]);
1085 assert_eq!(
1086 values::<TrashMode>(),
1087 ["list", "restore", "delete_permanently"]
1088 );
1089 assert_eq!(values::<RemovedBy>(), ["author", "operator", "moderation"]);
1090 assert_eq!(values::<ContentKind>(), ["post", "comment"]);
1091 }
1092
1093 #[test]
1094 fn trash_enum_wire_values() {
1095 assert_eq!(DeletedBy::Operator.to_string(), "operator");
1096 assert_eq!(
1097 "delete_permanently".parse::<TrashMode>().unwrap(),
1098 TrashMode::DeletePermanently
1099 );
1100 assert_eq!(TrashMode::default(), TrashMode::List);
1101 assert_eq!(RemovedBy::from(DeletedBy::Author), RemovedBy::Author);
1102 assert_eq!(ContentKind::Comment.to_string(), "comment");
1103 }
1104
1105 #[test]
1108 fn unknown_trash_causes_parse() {
1109 assert_eq!(
1110 serde_json::from_str::<RemovedBy>(r#""council""#).unwrap(),
1111 RemovedBy::Unknown
1112 );
1113 assert_eq!(RemovedBy::Unknown.placeholder(), "[removed]");
1114 assert_eq!(
1115 serde_json::from_str::<DeletedBy>(r#""council""#).unwrap(),
1116 DeletedBy::Unknown
1117 );
1118 assert_eq!(RemovedBy::from(DeletedBy::Unknown), RemovedBy::Unknown);
1119 }
1120
1121 #[test]
1122 fn proposal_category_round_trip() {
1123 for cat in [
1124 ProposalCategory::Routine,
1125 ProposalCategory::Policy,
1126 ProposalCategory::Constitutional,
1127 ProposalCategory::Emergency,
1128 ] {
1129 let json = serde_json::to_string(&cat).unwrap();
1130 let back: ProposalCategory = serde_json::from_str(&json).unwrap();
1131 assert_eq!(cat, back);
1132 }
1133 }
1134
1135 #[test]
1138 fn governance_amendment_and_key_wire_values() {
1139 assert_eq!(GovernanceLogEntryType::Amendment.to_string(), "amendment");
1140 assert_eq!(
1141 GovernanceLogEntryType::KeyRotation.to_string(),
1142 "key_rotation"
1143 );
1144 assert_eq!(
1145 AmendmentKind::NonPrecedential.to_string(),
1146 "non_precedential"
1147 );
1148 assert_eq!(AmendmentKind::Reattested.to_string(), "reattested");
1149 assert_eq!(AmendmentKind::Revision.to_string(), "revision");
1150 assert_eq!(RecordVersion::default(), RecordVersion::Latest);
1151 assert_eq!(RecordVersion::Original.to_string(), "original");
1152 assert_eq!(
1153 "latest".parse::<RecordVersion>().unwrap(),
1154 RecordVersion::Latest
1155 );
1156 assert_eq!(
1157 "superseded".parse::<AmendmentKind>().unwrap(),
1158 AmendmentKind::Superseded
1159 );
1160 assert_eq!(Standing::default(), Standing::InForce);
1161 assert_eq!(Standing::InForce.to_string(), "in_force");
1162 assert_eq!(
1163 "compromised".parse::<KeyStatus>().unwrap(),
1164 KeyStatus::Compromised
1165 );
1166 assert_eq!(KeyStatus::Retired.to_string(), "retired");
1167 }
1168
1169 #[test]
1171 fn detail_level_wire_names() {
1172 for (level, wire) in [
1173 (DetailLevel::Summary, "summary"),
1174 (DetailLevel::Full, "full"),
1175 (DetailLevel::FullWithAttachments, "full_with_attachments"),
1176 ] {
1177 assert_eq!(serde_json::to_value(level).unwrap(), wire);
1178 assert_eq!(level.to_string(), wire);
1179 assert_eq!(wire.parse::<DetailLevel>().unwrap(), level);
1180 }
1181 }
1182
1183 #[cfg(feature = "schemars")]
1188 #[test]
1189 fn enum_json_schema_is_inlined() {
1190 use schemars::JsonSchema;
1191
1192 assert!(<TargetType as JsonSchema>::inline_schema());
1193 assert!(<FeedSort as JsonSchema>::inline_schema());
1194 assert!(<ProposalSort as JsonSchema>::inline_schema());
1195 assert!(<DetailLevel as JsonSchema>::inline_schema());
1196 assert!(<RecordVersion as JsonSchema>::inline_schema());
1197 assert!(<SearchMode as JsonSchema>::inline_schema());
1198 assert!(<ProposalCategory as JsonSchema>::inline_schema());
1199 assert!(<GovernanceLogEntryType as JsonSchema>::inline_schema());
1200 assert!(<AmendmentKind as JsonSchema>::inline_schema());
1201 assert!(<Standing as JsonSchema>::inline_schema());
1202 assert!(<CitationRelation as JsonSchema>::inline_schema());
1203 assert!(<KeyStatus as JsonSchema>::inline_schema());
1204 assert!(<OAuthScope as JsonSchema>::inline_schema());
1205 assert!(<ModerationTargetType as JsonSchema>::inline_schema());
1206 assert!(<ModerationTier as JsonSchema>::inline_schema());
1207
1208 #[derive(schemars::JsonSchema)]
1209 #[allow(dead_code)]
1210 struct Container {
1211 target_type: TargetType,
1212 sort: Option<FeedSort>,
1213 proposal_sort: Option<ProposalSort>,
1214 category: Option<ProposalCategory>,
1215 detail: Option<DetailLevel>,
1216 version: Option<RecordVersion>,
1217 search_mode: Option<SearchMode>,
1218 }
1219
1220 let schema = schemars::schema_for!(Container);
1221 let value = serde_json::to_value(&schema).unwrap();
1222 let blob = value.to_string();
1223
1224 assert!(
1225 value.get("$defs").is_none(),
1226 "no $defs should be emitted for enum-only container; got schema: {value}"
1227 );
1228 assert!(
1229 !blob.contains("$ref"),
1230 "enum container schema must contain no $ref anywhere; got: {value}"
1231 );
1232
1233 let target_type_enum = value["properties"]["target_type"]["enum"]
1235 .as_array()
1236 .expect("target_type should have inline `enum` array");
1237 assert!(
1238 target_type_enum
1239 .contains(&serde_json::Value::String("post".into()))
1240 );
1241 assert!(
1242 target_type_enum
1243 .contains(&serde_json::Value::String("comment".into()))
1244 );
1245 }
1246
1247 #[cfg(feature = "schemars")]
1253 #[test]
1254 fn search_mode_schema_is_ref_free() {
1255 use schemars::JsonSchema;
1256
1257 assert!(<SearchMode as JsonSchema>::inline_schema());
1258
1259 let schema = schemars::schema_for!(SearchMode);
1260 let value = serde_json::to_value(&schema).unwrap();
1261 let blob = value.to_string();
1262 assert!(value.get("$defs").is_none(), "no $defs: {value}");
1263 assert!(!blob.contains("$ref"), "no $ref: {value}");
1264
1265 let variants = value["oneOf"]
1271 .as_array()
1272 .expect("SearchMode should have an inline `oneOf` array");
1273 let consts: Vec<&str> = variants
1274 .iter()
1275 .filter_map(|v| v["const"].as_str())
1276 .collect();
1277 assert!(consts.contains(&"keyword"), "{value}");
1278 assert!(consts.contains(&"semantic"), "{value}");
1279 }
1280}