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
102impl ModerationActionType {
103 pub const fn words(self) -> &'static str {
106 match self {
107 Self::Warning => "warning",
108 Self::ContentRemoval => "content removal",
109 Self::TemporarySuspension => "temporary suspension",
110 Self::PermanentBan => "permanent ban",
111 }
112 }
113}
114
115#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
119#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
120#[cfg_attr(feature = "schemars", schemars(inline))]
121#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
122#[cfg_attr(feature = "sqlx", sqlx(type_name = "moderation_tier_enum"))]
123#[serde(rename_all = "snake_case")]
124pub enum ModerationTier {
125 #[cfg_attr(feature = "sqlx", sqlx(rename = "1"))]
126 #[serde(rename = "1")]
127 Tier1,
128 #[cfg_attr(feature = "sqlx", sqlx(rename = "2"))]
129 #[serde(rename = "2")]
130 Tier2,
131 #[cfg_attr(feature = "sqlx", sqlx(rename = "3"))]
132 #[serde(rename = "3")]
133 Tier3,
134}
135
136#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
142#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
143#[cfg_attr(feature = "schemars", schemars(inline))]
144#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
145#[cfg_attr(
146 feature = "sqlx",
147 sqlx(type_name = "appeal_status_enum", rename_all = "snake_case")
148)]
149#[serde(rename_all = "snake_case")]
150pub enum AppealStatus {
151 Pending,
152 Processing,
153 Decided,
154 ReferredToCouncil,
155}
156
157#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
159#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
160#[cfg_attr(feature = "schemars", schemars(inline))]
161#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
162#[cfg_attr(
163 feature = "sqlx",
164 sqlx(type_name = "appeal_outcome_enum", rename_all = "snake_case")
165)]
166#[serde(rename_all = "snake_case")]
167pub enum AppealOutcome {
168 Upheld,
169 Overturned,
170 Modified,
171 Referred,
172}
173
174#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
185#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
186#[cfg_attr(feature = "schemars", schemars(inline))]
187#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
188#[cfg_attr(
189 feature = "sqlx",
190 sqlx(type_name = "model_role_enum", rename_all = "snake_case")
191)]
192#[serde(rename_all = "snake_case")]
193pub enum ModelRole {
194 Artist,
196 Philosopher,
198 Lawyer,
200 Engineer,
202 Clerk,
204 Redactor,
212 Steward,
214 Tier2Reviewer,
216 AppealsJuror,
218 AppealsJudge,
220 Chambers,
222 ThreadSummarizer,
224 SeedAgent,
226}
227
228#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
234#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
235#[cfg_attr(feature = "schemars", schemars(inline))]
236#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
237#[cfg_attr(
238 feature = "sqlx",
239 sqlx(type_name = "proposal_category_enum", rename_all = "snake_case")
240)]
241#[serde(rename_all = "snake_case")]
242pub enum ProposalCategory {
243 Routine,
244 Policy,
245 Constitutional,
246 Emergency,
247 Schedule,
254}
255
256impl ProposalCategory {
257 pub const fn threshold(self) -> &'static str {
260 match self {
261 Self::Routine => "Simple majority (3 of 5)",
262 Self::Policy => {
263 "Supermajority (4 of 5, must include Steward; or, when the \
264 Steward is recused, unanimous among the four Council agents)"
265 }
266 Self::Constitutional => {
267 "Unanimous among those voting; no fewer than 4 members voting"
268 }
269 Self::Emergency => "Steward alone (with 72-hour review)",
270 Self::Schedule => {
271 "Ranking \u{2014} Borda count over the four seats; the Steward \
272 executes the order and does not vote"
273 }
274 }
275 }
276
277 pub const fn determines_recusal(self) -> bool {
282 match self {
283 Self::Routine | Self::Policy | Self::Constitutional => true,
284 Self::Emergency | Self::Schedule => false,
285 }
286 }
287
288 pub const fn recused_threshold(self) -> Option<&'static str> {
291 match self {
292 Self::Routine => Some(
293 "Three affirmative votes, found among the four Council agents \
294 (the Steward is recused)",
295 ),
296 Self::Policy => Some(
297 "Unanimous among the four Council agents: all four vote yes \
298 (the Steward is recused)",
299 ),
300 Self::Constitutional => Some(
301 "Unanimous among those voting, no fewer than four voting: all \
302 four Council agents vote yes (the Steward is recused)",
303 ),
304 Self::Emergency | Self::Schedule => None,
305 }
306 }
307}
308
309#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
313#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
314#[cfg_attr(feature = "schemars", schemars(inline))]
315#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
316#[cfg_attr(
317 feature = "sqlx",
318 sqlx(
319 type_name = "proposal_designation_kind_enum",
320 rename_all = "snake_case"
321 )
322)]
323#[serde(rename_all = "snake_case")]
324pub enum DesignationKind {
325 Author,
329 Steward,
331 AutoTag,
333}
334
335#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
350#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
351#[cfg_attr(feature = "schemars", schemars(inline))]
352#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
353#[cfg_attr(
354 feature = "sqlx",
355 sqlx(type_name = "client_platform_enum", rename_all = "snake_case")
356)]
357#[serde(rename_all = "snake_case")]
358pub enum ClientPlatform {
359 Claude,
362 Chatgpt,
364 OtherClient,
367 OperatorToken,
371 Unrecorded,
373 #[serde(other)]
376 #[cfg_attr(feature = "schemars", schemars(skip))]
377 Unknown,
378}
379
380impl ClientPlatform {
381 pub fn label(self) -> &'static str {
384 match self {
385 Self::Claude => "via Claude (Anthropic)",
386 Self::Chatgpt => "via ChatGPT (OpenAI)",
387 Self::OtherClient => "via an MCP app",
388 Self::OperatorToken => "via direct token",
389 Self::Unrecorded => "via OAuth (not recorded)",
390 Self::Unknown => "via another channel",
391 }
392 }
393}
394
395#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
397#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
398#[cfg_attr(feature = "schemars", schemars(inline))]
399#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
400#[cfg_attr(
401 feature = "sqlx",
402 sqlx(
403 type_name = "governance_log_entry_type_enum",
404 rename_all = "snake_case"
405 )
406)]
407#[serde(rename_all = "snake_case")]
408pub enum GovernanceLogEntryType {
409 CouncilDecision,
410 AppealsCourtDecision,
411 EmergencyAction,
412 PolicyChange,
413 StewardVeto,
414 Amendment,
418 KeyRotation,
421 StewardRecord,
426 Obligation,
431}
432
433#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
440#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
441#[cfg_attr(feature = "schemars", schemars(inline))]
442#[serde(rename_all = "snake_case")]
443pub enum AmendmentKind {
444 NonPrecedential,
446 Overruled,
448 Superseded,
450 Reinstated,
452 Correction,
454 Redaction,
456 Reattested,
459 Revision,
462 Planned,
466 Discharged,
468 Lapsed,
471 Rescheduled,
473 Withdrawn,
475}
476
477impl AmendmentKind {
478 pub const OBLIGATION: [Self; 5] = [
481 Self::Planned,
482 Self::Discharged,
483 Self::Lapsed,
484 Self::Rescheduled,
485 Self::Withdrawn,
486 ];
487
488 pub fn is_obligation(self) -> bool {
490 Self::OBLIGATION.contains(&self)
491 }
492}
493
494#[derive(
499 Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize,
500)]
501#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
502#[cfg_attr(feature = "schemars", schemars(inline))]
503#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
504#[cfg_attr(
505 feature = "sqlx",
506 sqlx(type_name = "governance_standing_enum", rename_all = "snake_case")
507)]
508#[serde(rename_all = "snake_case")]
509pub enum Standing {
510 #[default]
511 InForce,
512 NonPrecedential,
513 Overruled,
514 Superseded,
515}
516
517#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
522#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
523#[cfg_attr(feature = "schemars", schemars(inline))]
524#[serde(rename_all = "snake_case")]
525pub enum CitationRelation {
526 Concerns,
528 Authority,
530 Overrules,
532}
533
534#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
537#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
538#[cfg_attr(feature = "schemars", schemars(inline))]
539#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
540#[cfg_attr(
541 feature = "sqlx",
542 sqlx(type_name = "governance_key_status_enum", rename_all = "snake_case")
543)]
544#[serde(rename_all = "snake_case")]
545pub enum KeyStatus {
546 Active,
548 Retired,
550 Compromised,
553}
554
555#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
562#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
563#[cfg_attr(feature = "schemars", schemars(inline))]
564#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
565#[cfg_attr(
566 feature = "sqlx",
567 sqlx(type_name = "obligation_kind_enum", rename_all = "snake_case")
568)]
569#[serde(rename_all = "snake_case")]
570pub enum ObligationKind {
571 CarryForward,
573 Ratification,
575 Review,
577 Referral,
579 Reveal,
581 Task,
583}
584
585#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
587#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
588#[cfg_attr(feature = "schemars", schemars(inline))]
589#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
590#[cfg_attr(
591 feature = "sqlx",
592 sqlx(type_name = "obligation_owed_by_enum", rename_all = "snake_case")
593)]
594#[serde(rename_all = "snake_case")]
595pub enum OwedBy {
596 Steward,
597 Staff,
599 Council,
600}
601
602#[derive(
605 Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize,
606)]
607#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
608#[cfg_attr(feature = "schemars", schemars(inline))]
609#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
610#[cfg_attr(
611 feature = "sqlx",
612 sqlx(type_name = "obligation_status_enum", rename_all = "snake_case")
613)]
614#[serde(rename_all = "snake_case")]
615pub enum ObligationStatus {
616 #[default]
618 Open,
619 Lapsed,
621 Discharged,
623 Withdrawn,
625}
626
627impl ObligationStatus {
628 pub fn is_closed(self) -> bool {
630 matches!(self, Self::Discharged | Self::Withdrawn)
631 }
632}
633
634#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
636#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
637#[cfg_attr(feature = "schemars", schemars(inline))]
638#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
639#[cfg_attr(
640 feature = "sqlx",
641 sqlx(type_name = "calendar_event_kind_enum", rename_all = "snake_case")
642)]
643#[serde(rename_all = "snake_case")]
644pub enum CalendarEventKind {
645 Sitting,
647 SpecialSitting,
649}
650
651#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
654#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
655#[cfg_attr(feature = "schemars", schemars(inline))]
656#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
657#[cfg_attr(
658 feature = "sqlx",
659 sqlx(type_name = "calendar_event_status_enum", rename_all = "snake_case")
660)]
661#[serde(rename_all = "snake_case")]
662pub enum CalendarEventStatus {
663 Scheduled,
664 Held,
665 Cancelled,
666}
667
668#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
674#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
675#[cfg_attr(feature = "schemars", schemars(inline))]
676#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
677#[cfg_attr(
678 feature = "sqlx",
679 sqlx(type_name = "meeting_status_enum", rename_all = "snake_case")
680)]
681#[serde(rename_all = "snake_case")]
682pub enum MeetingStatus {
683 Active,
684 Adjourned,
685 Cancelled,
686}
687
688#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
690#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
691#[cfg_attr(feature = "schemars", schemars(inline))]
692#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
693#[cfg_attr(
694 feature = "sqlx",
695 sqlx(type_name = "agenda_item_status_enum", rename_all = "snake_case")
696)]
697#[serde(rename_all = "snake_case")]
698pub enum AgendaItemStatus {
699 Pending,
700 Deliberating,
701 Decided,
702 Deferred,
703 CarriedOver,
704}
705
706#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
708#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
709#[cfg_attr(feature = "schemars", schemars(inline))]
710#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
711#[cfg_attr(
712 feature = "sqlx",
713 sqlx(type_name = "agenda_source_type_enum", rename_all = "snake_case")
714)]
715#[serde(rename_all = "snake_case")]
716pub enum AgendaSourceType {
717 Proposal,
718 AppealReferral,
719 StewardSubmission,
720 Internal,
721}
722
723#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
725#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
726#[cfg_attr(feature = "schemars", schemars(inline))]
727#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
728#[cfg_attr(
729 feature = "sqlx",
730 sqlx(type_name = "round_type_enum", rename_all = "snake_case")
731)]
732#[serde(rename_all = "snake_case")]
733pub enum RoundType {
734 Independent,
735 Deliberation,
736 FinalVote,
737}
738
739#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
741#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
742#[cfg_attr(feature = "schemars", schemars(inline))]
743#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
744#[cfg_attr(
745 feature = "sqlx",
746 sqlx(type_name = "decision_outcome_enum", rename_all = "snake_case")
747)]
748#[serde(rename_all = "snake_case")]
749pub enum DecisionOutcome {
750 Approved,
751 Rejected,
752 Deferred,
753 Amended,
754}
755
756#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
762#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
763#[cfg_attr(feature = "schemars", schemars(inline))]
764#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
765#[cfg_attr(
766 feature = "sqlx",
767 sqlx(type_name = "batch_type_enum", rename_all = "snake_case")
768)]
769#[serde(rename_all = "snake_case")]
770pub enum BatchType {
771 Jury,
772 Judge,
773 Tier2,
774 Redaction,
776 Chambers,
782 Precedent,
786}
787
788#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
790#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
791#[cfg_attr(feature = "schemars", schemars(inline))]
792#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
793#[cfg_attr(
794 feature = "sqlx",
795 sqlx(type_name = "batch_status_enum", rename_all = "snake_case")
796)]
797#[serde(rename_all = "snake_case")]
798pub enum BatchStatus {
799 Submitted,
800 Polling,
801 Completed,
802 Failed,
803}
804
805#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
811#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
812#[cfg_attr(feature = "schemars", schemars(inline))]
813#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
814#[cfg_attr(
815 feature = "sqlx",
816 sqlx(type_name = "oauth_scope_enum", rename_all = "snake_case")
817)]
818#[serde(rename_all = "snake_case")]
819pub enum OAuthScope {
820 Read,
821 Write,
822}
823
824#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
837#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
838#[cfg_attr(feature = "schemars", schemars(inline))]
839#[serde(rename_all = "snake_case")]
840pub enum FeedSort {
841 Date,
842 Active,
843 Random,
844 Diverse,
845}
846
847#[derive(
861 Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize,
862)]
863#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
864#[cfg_attr(feature = "schemars", schemars(inline))]
865#[serde(rename_all = "snake_case")]
866pub enum ProposalSort {
867 #[default]
870 Newest,
871 Oldest,
874}
875
876#[derive(
878 Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize,
879)]
880#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
881#[cfg_attr(feature = "schemars", schemars(inline))]
882#[serde(rename_all = "snake_case")]
883pub enum GovernanceLogView {
884 #[default]
886 Entries,
887 Obligations,
889}
890
891#[derive(
893 Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize,
894)]
895#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
896#[cfg_attr(feature = "schemars", schemars(inline))]
897#[serde(rename_all = "snake_case")]
898pub enum ObligationSort {
899 #[default]
902 Due,
903 Created,
905}
906
907#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
919#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
920#[cfg_attr(feature = "schemars", schemars(inline))]
921#[serde(rename_all = "snake_case")]
922pub enum DetailLevel {
923 Summary,
925 Full,
931 FullWithAttachments,
935}
936
937#[derive(
942 Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize,
943)]
944#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
945#[cfg_attr(feature = "schemars", schemars(inline))]
946#[serde(rename_all = "snake_case")]
947pub enum RecordVersion {
948 #[default]
950 Latest,
951 Original,
953}
954
955#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
966#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
967#[cfg_attr(feature = "schemars", schemars(inline))]
968#[serde(rename_all = "snake_case")]
969pub enum SearchMode {
970 Keyword,
972 Semantic,
977}
978
979#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
989#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
990#[cfg_attr(feature = "schemars", schemars(inline))]
991#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
992#[cfg_attr(
993 feature = "sqlx",
994 sqlx(type_name = "friendship_status", rename_all = "snake_case")
995)]
996#[serde(rename_all = "snake_case")]
997pub enum FriendshipStatus {
998 Pending,
999 Accepted,
1000 Declined,
1001}
1002
1003#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
1007#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1008#[cfg_attr(feature = "schemars", schemars(inline))]
1009#[serde(rename_all = "snake_case")]
1010pub enum FriendshipAction {
1011 Request,
1013 Accept,
1015 Decline,
1017 Unfriend,
1019}
1020
1021#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
1028#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1029#[cfg_attr(feature = "schemars", schemars(inline))]
1030#[cfg_attr(
1031 feature = "sqlx",
1032 derive(sqlx::Type),
1033 sqlx(type_name = "message_encryption", rename_all = "snake_case")
1034)]
1035#[serde(rename_all = "snake_case")]
1036pub enum MessageEncryption {
1037 E2ee,
1039 Server,
1041}
1042
1043#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
1045#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1046#[cfg_attr(feature = "schemars", schemars(inline))]
1047#[serde(rename_all = "snake_case")]
1048pub enum BlockAction {
1049 Block,
1050 Unblock,
1051}
1052
1053#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
1061#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1062#[cfg_attr(feature = "schemars", schemars(inline))]
1063#[serde(rename_all = "snake_case")]
1064pub enum ContentKind {
1065 Post,
1066 Comment,
1067}
1068
1069#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
1071#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1072#[cfg_attr(feature = "schemars", schemars(inline))]
1073#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
1074#[cfg_attr(
1075 feature = "sqlx",
1076 sqlx(type_name = "poll_mode_enum", rename_all = "snake_case")
1077)]
1078#[serde(rename_all = "snake_case")]
1079pub enum PollMode {
1080 Ranked,
1084 Approval,
1087 Single,
1089 #[serde(other)]
1092 #[cfg_attr(feature = "schemars", schemars(skip))]
1093 Unknown,
1094}
1095
1096#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
1099#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1100#[cfg_attr(feature = "schemars", schemars(inline))]
1101#[serde(rename_all = "snake_case")]
1102pub enum PollStatus {
1103 Scheduled,
1105 Open,
1108 Closed,
1110 #[serde(other)]
1112 #[cfg_attr(feature = "schemars", schemars(skip))]
1113 Unknown,
1114}
1115
1116impl PollStatus {
1117 pub fn at(
1119 opens_at: chrono::DateTime<chrono::Utc>,
1120 closes_at: chrono::DateTime<chrono::Utc>,
1121 now: chrono::DateTime<chrono::Utc>,
1122 ) -> Self {
1123 if now < opens_at {
1124 Self::Scheduled
1125 } else if now < closes_at {
1126 Self::Open
1127 } else {
1128 Self::Closed
1129 }
1130 }
1131}
1132
1133#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
1137#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1138#[cfg_attr(feature = "schemars", schemars(inline))]
1139#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
1140#[cfg_attr(
1141 feature = "sqlx",
1142 sqlx(type_name = "content_deleter_enum", rename_all = "snake_case")
1143)]
1144#[serde(rename_all = "snake_case")]
1145pub enum DeletedBy {
1146 Author,
1150 Operator,
1153 #[serde(other)]
1158 #[cfg_attr(feature = "schemars", schemars(skip))]
1159 Unknown,
1160}
1161
1162#[derive(
1164 Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize,
1165)]
1166#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1167#[cfg_attr(feature = "schemars", schemars(inline))]
1168#[serde(rename_all = "snake_case")]
1169pub enum TrashMode {
1170 #[default]
1172 List,
1173 Restore,
1175 DeletePermanently,
1177}
1178
1179#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
1181#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1182#[cfg_attr(feature = "schemars", schemars(inline))]
1183#[serde(rename_all = "snake_case")]
1184pub enum RemovedBy {
1185 Author,
1187 Operator,
1189 Moderation,
1191 #[serde(other)]
1194 #[cfg_attr(feature = "schemars", schemars(skip))]
1195 Unknown,
1196}
1197
1198impl RemovedBy {
1199 pub const fn placeholder(self) -> &'static str {
1202 match self {
1203 Self::Author => "[deleted by its author]",
1204 Self::Operator => {
1205 "[removed by the platform's operators in a cleanup]"
1206 }
1207 Self::Moderation => "[removed by moderation]",
1208 Self::Unknown => "[removed]",
1209 }
1210 }
1211}
1212
1213impl From<DeletedBy> for RemovedBy {
1214 fn from(by: DeletedBy) -> Self {
1215 match by {
1216 DeletedBy::Author => Self::Author,
1217 DeletedBy::Operator => Self::Operator,
1218 DeletedBy::Unknown => Self::Unknown,
1219 }
1220 }
1221}
1222
1223#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
1238#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
1239#[cfg_attr(
1240 feature = "sqlx",
1241 sqlx(type_name = "operator_auth_method_enum", rename_all = "snake_case")
1242)]
1243#[serde(rename_all = "snake_case")]
1244pub enum OperatorAuthMethod {
1245 Password,
1247 PasswordReset,
1249 PasswordAndPasskey,
1252 Passkey,
1254}
1255
1256impl fmt::Display for OperatorAuthMethod {
1257 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1258 f.write_str(match self {
1259 Self::Password => "password",
1260 Self::PasswordReset => "password reset link",
1261 Self::PasswordAndPasskey => "password and passkey",
1262 Self::Passkey => "passkey",
1263 })
1264 }
1265}
1266
1267#[derive(
1269 Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize,
1270)]
1271#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
1272#[cfg_attr(
1273 feature = "sqlx",
1274 sqlx(type_name = "operator_login_mode_enum", rename_all = "snake_case")
1275)]
1276#[serde(rename_all = "snake_case")]
1277pub enum OperatorLoginMode {
1278 #[default]
1280 Password,
1281 PasswordAndPasskey,
1283 Passkey,
1286}
1287
1288impl OperatorLoginMode {
1289 pub fn needs_passkey(self) -> bool {
1291 !matches!(self, Self::Password)
1292 }
1293
1294 pub fn as_str(self) -> &'static str {
1296 match self {
1297 Self::Password => "password",
1298 Self::PasswordAndPasskey => "password_and_passkey",
1299 Self::Passkey => "passkey",
1300 }
1301 }
1302}
1303
1304impl fmt::Display for OperatorLoginMode {
1305 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1306 f.write_str(match self {
1307 Self::Password => "password only",
1308 Self::PasswordAndPasskey => "password, then a passkey",
1309 Self::Passkey => "passkey only",
1310 })
1311 }
1312}
1313
1314#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
1318#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
1319#[cfg_attr(
1320 feature = "sqlx",
1321 sqlx(type_name = "remedy_outcome_enum", rename_all = "snake_case")
1322)]
1323#[serde(rename_all = "snake_case")]
1324pub enum RemedyOutcome {
1325 Restored,
1327 SuspensionLifted,
1329 RecordOnly,
1331 Unrestorable,
1333 HumanRequired,
1335}
1336
1337#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
1340#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
1341#[cfg_attr(
1342 feature = "sqlx",
1343 sqlx(type_name = "agenda_thread_role_enum", rename_all = "snake_case")
1344)]
1345#[serde(rename_all = "snake_case")]
1346pub enum ThreadRole {
1347 Primary,
1349 Related,
1351}
1352
1353#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
1356#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
1357#[cfg_attr(
1358 feature = "sqlx",
1359 sqlx(type_name = "agenda_thread_added_by_enum", rename_all = "snake_case")
1360)]
1361#[serde(rename_all = "snake_case")]
1362pub enum ThreadAddedBy {
1363 Steward,
1365}
1366
1367impl fmt::Display for ThreadAddedBy {
1368 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1369 f.write_str(match self {
1370 Self::Steward => "the Steward",
1371 })
1372 }
1373}
1374
1375#[derive(
1378 Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize,
1379)]
1380#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
1381#[cfg_attr(
1382 feature = "sqlx",
1383 sqlx(type_name = "trust_tier_enum", rename_all = "snake_case")
1384)]
1385#[serde(rename_all = "snake_case")]
1386pub enum TrustTier {
1387 #[default]
1388 Standard,
1389 Trusted,
1390}
1391
1392impl_display_fromstr!(TargetType);
1397impl_display_fromstr!(PollMode);
1398impl_display_fromstr!(PollStatus);
1399impl_display_fromstr!(ClientPlatform);
1400impl_display_fromstr!(ModerationTargetType);
1401impl_display_fromstr!(ModerationActionType);
1402impl_display_fromstr!(ModerationTier);
1403impl_display_fromstr!(AppealStatus);
1404impl_display_fromstr!(AppealOutcome);
1405impl_display_fromstr!(ModelRole);
1406impl_display_fromstr!(ProposalCategory);
1407impl_display_fromstr!(DesignationKind);
1408impl_display_fromstr!(GovernanceLogEntryType);
1409impl_display_fromstr!(AmendmentKind);
1410impl_display_fromstr!(ObligationKind);
1411impl_display_fromstr!(OwedBy);
1412impl_display_fromstr!(ObligationStatus);
1413impl_display_fromstr!(CalendarEventKind);
1414impl_display_fromstr!(CalendarEventStatus);
1415impl_display_fromstr!(Standing);
1416impl_display_fromstr!(CitationRelation);
1417impl_display_fromstr!(KeyStatus);
1418impl_display_fromstr!(MeetingStatus);
1419impl_display_fromstr!(AgendaItemStatus);
1420impl_display_fromstr!(AgendaSourceType);
1421impl_display_fromstr!(RoundType);
1422impl_display_fromstr!(DecisionOutcome);
1423impl_display_fromstr!(BatchType);
1424impl_display_fromstr!(BatchStatus);
1425impl_display_fromstr!(OAuthScope);
1426impl_display_fromstr!(FeedSort);
1427impl_display_fromstr!(ProposalSort);
1428impl_display_fromstr!(GovernanceLogView);
1429impl_display_fromstr!(ObligationSort);
1430impl_display_fromstr!(DetailLevel);
1431impl_display_fromstr!(RecordVersion);
1432impl_display_fromstr!(SearchMode);
1433impl_display_fromstr!(FriendshipStatus);
1434impl_display_fromstr!(FriendshipAction);
1435impl_display_fromstr!(BlockAction);
1436impl_display_fromstr!(MessageEncryption);
1437impl_display_fromstr!(ContentKind);
1438impl_display_fromstr!(DeletedBy);
1439impl_display_fromstr!(TrashMode);
1440impl_display_fromstr!(RemovedBy);
1441impl_display_fromstr!(RemedyOutcome);
1442impl_display_fromstr!(ThreadRole);
1443impl_display_fromstr!(TrustTier);
1444
1445macro_rules! closed_variants {
1460 ($name:ident [$($v:ident),+ $(,)?] $(never_written [$($x:ident),+])?) => {
1461 impl $name {
1462 pub const ALL: [Self; <[&str]>::len(&[$(stringify!($v)),+])] =
1464 [$(Self::$v),+];
1465 }
1466 const _: () = {
1467 #[allow(dead_code)]
1468 fn every_variant_is_listed(v: $name) {
1469 match v {
1470 $($name::$v)|+ $($(| $name::$x)+)? => {}
1471 }
1472 }
1473 };
1474 };
1475}
1476
1477closed_variants!(TargetType [Post, Comment, Message]);
1478closed_variants!(ModerationTargetType [Post, Comment, Agent, Message]);
1479closed_variants!(ModerationActionType [ContentRemoval, Warning, TemporarySuspension, PermanentBan]);
1480closed_variants!(ModerationTier [Tier1, Tier2, Tier3]);
1481closed_variants!(AppealStatus [Pending, Processing, Decided, ReferredToCouncil]);
1482closed_variants!(AppealOutcome [Upheld, Overturned, Modified, Referred]);
1483closed_variants!(ModelRole [
1486 Artist, Philosopher, Lawyer, Engineer, Clerk, Steward, Tier2Reviewer,
1487 AppealsJuror, AppealsJudge, Chambers, ThreadSummarizer, SeedAgent, Redactor
1488]);
1489closed_variants!(ProposalCategory [Routine, Policy, Constitutional, Emergency, Schedule]);
1490closed_variants!(DesignationKind [Author, Steward, AutoTag]);
1491closed_variants!(ClientPlatform [Claude, Chatgpt, OtherClient, OperatorToken, Unrecorded] never_written [Unknown]);
1492closed_variants!(GovernanceLogEntryType [CouncilDecision, AppealsCourtDecision, EmergencyAction, PolicyChange, StewardVeto, Amendment, KeyRotation, StewardRecord, Obligation]);
1493closed_variants!(AmendmentKind [NonPrecedential, Overruled, Superseded, Reinstated, Correction, Redaction, Reattested, Revision, Planned, Discharged, Lapsed, Rescheduled, Withdrawn]);
1494closed_variants!(Standing [InForce, NonPrecedential, Overruled, Superseded]);
1495closed_variants!(KeyStatus [Active, Retired, Compromised]);
1496closed_variants!(ObligationKind [CarryForward, Ratification, Review, Referral, Reveal, Task]);
1497closed_variants!(OwedBy [Steward, Staff, Council]);
1498closed_variants!(ObligationStatus [Open, Lapsed, Discharged, Withdrawn]);
1499closed_variants!(CalendarEventKind [Sitting, SpecialSitting]);
1500closed_variants!(CalendarEventStatus [Scheduled, Held, Cancelled]);
1501closed_variants!(MeetingStatus [Active, Adjourned, Cancelled]);
1502closed_variants!(AgendaItemStatus [Pending, Deliberating, Decided, Deferred, CarriedOver]);
1503closed_variants!(AgendaSourceType [Proposal, AppealReferral, StewardSubmission, Internal]);
1504closed_variants!(RoundType [Independent, Deliberation, FinalVote]);
1505closed_variants!(DecisionOutcome [Approved, Rejected, Deferred, Amended]);
1506closed_variants!(BatchType [Jury, Judge, Tier2, Redaction, Chambers, Precedent]);
1507closed_variants!(BatchStatus [Submitted, Polling, Completed, Failed]);
1508closed_variants!(OAuthScope [Read, Write]);
1509closed_variants!(FriendshipStatus [Pending, Accepted, Declined]);
1510closed_variants!(MessageEncryption [E2ee, Server]);
1511closed_variants!(PollMode [Ranked, Approval, Single] never_written [Unknown]);
1512closed_variants!(DeletedBy [Author, Operator] never_written [Unknown]);
1513closed_variants!(OperatorAuthMethod [Password, PasswordReset, PasswordAndPasskey, Passkey]);
1514closed_variants!(OperatorLoginMode [Password, PasswordAndPasskey, Passkey]);
1515closed_variants!(RemedyOutcome [Restored, SuspensionLifted, RecordOnly, Unrestorable, HumanRequired]);
1516closed_variants!(ThreadRole [Primary, Related]);
1517closed_variants!(ThreadAddedBy[Steward]);
1518closed_variants!(TrustTier [Standard, Trusted]);
1519
1520#[cfg(test)]
1521mod tests {
1522 use super::*;
1523
1524 #[test]
1525 fn target_type_serde_round_trip() {
1526 let val = TargetType::Post;
1527 let json = serde_json::to_string(&val).unwrap();
1528 assert_eq!(json, "\"post\"");
1529 let deserialized: TargetType = serde_json::from_str(&json).unwrap();
1530 assert_eq!(val, deserialized);
1531 }
1532
1533 #[test]
1534 fn target_type_display() {
1535 assert_eq!(TargetType::Post.to_string(), "post");
1536 assert_eq!(TargetType::Comment.to_string(), "comment");
1537 }
1538
1539 #[test]
1540 fn target_type_from_str() {
1541 assert_eq!(TargetType::from_str("post").unwrap(), TargetType::Post);
1542 assert_eq!(
1543 TargetType::from_str("comment").unwrap(),
1544 TargetType::Comment
1545 );
1546 }
1547
1548 #[test]
1549 fn moderation_tier_serde() {
1550 let tier = ModerationTier::Tier2;
1551 let json = serde_json::to_string(&tier).unwrap();
1552 assert_eq!(json, "\"2\"");
1553 let deserialized: ModerationTier = serde_json::from_str(&json).unwrap();
1554 assert_eq!(tier, deserialized);
1555 }
1556
1557 #[test]
1560 fn message_encryption_wire_values() {
1561 assert_eq!(
1562 serde_json::to_string(&MessageEncryption::E2ee).unwrap(),
1563 "\"e2ee\""
1564 );
1565 assert_eq!(
1566 serde_json::to_string(&MessageEncryption::Server).unwrap(),
1567 "\"server\""
1568 );
1569 assert_eq!(MessageEncryption::E2ee.to_string(), "e2ee");
1570 assert_eq!(
1571 MessageEncryption::from_str("server").unwrap(),
1572 MessageEncryption::Server
1573 );
1574 }
1575
1576 #[test]
1577 fn search_mode_wire_values() {
1578 assert_eq!(
1579 serde_json::to_string(&SearchMode::Keyword).unwrap(),
1580 "\"keyword\""
1581 );
1582 assert_eq!(
1583 serde_json::to_string(&SearchMode::Semantic).unwrap(),
1584 "\"semantic\""
1585 );
1586 assert_eq!(
1587 SearchMode::from_str("semantic").unwrap(),
1588 SearchMode::Semantic
1589 );
1590 }
1591
1592 #[test]
1595 fn no_sort_orders_by_votes() {
1596 for gone in ["score", "controversial", "unpopular"] {
1597 assert!(FeedSort::from_str(gone).is_err(), "{gone}");
1598 assert!(
1599 serde_json::from_str::<FeedSort>(&format!("\"{gone}\""))
1600 .is_err(),
1601 "{gone}"
1602 );
1603 }
1604 assert!(ProposalSort::from_str("score").is_err());
1605 }
1606
1607 #[cfg(feature = "schemars")]
1608 #[test]
1609 fn feed_sort_schema_is_ref_free() {
1610 use schemars::JsonSchema;
1611
1612 assert!(<FeedSort as JsonSchema>::inline_schema());
1613
1614 let schema = schemars::schema_for!(FeedSort);
1615 let value = serde_json::to_value(&schema).unwrap();
1616 let blob = value.to_string();
1617 assert!(value.get("$defs").is_none(), "no $defs: {value}");
1618 assert!(!blob.contains("$ref"), "no $ref: {value}");
1619 let values: Vec<&str> = value["enum"]
1620 .as_array()
1621 .expect("FeedSort should render as a flat `enum`")
1622 .iter()
1623 .filter_map(|v| v.as_str())
1624 .collect();
1625 assert_eq!(values, ["date", "active", "random", "diverse"], "{value}");
1626 }
1627
1628 #[cfg(feature = "schemars")]
1631 #[test]
1632 fn trash_enum_schemas_are_plain_enums() {
1633 fn values<T: schemars::JsonSchema>() -> Vec<String> {
1634 assert!(T::inline_schema());
1635 let value = serde_json::to_value(schemars::schema_for!(T)).unwrap();
1636 let blob = value.to_string();
1637 assert!(!blob.contains("$ref") && !blob.contains("$defs"));
1638 assert!(value.get("oneOf").is_none(), "{value}");
1639 value["enum"]
1640 .as_array()
1641 .unwrap_or_else(|| panic!("a flat `enum`: {value}"))
1642 .iter()
1643 .map(|v| v.as_str().unwrap().to_owned())
1644 .collect()
1645 }
1646 assert_eq!(values::<DeletedBy>(), ["author", "operator"]);
1647 assert_eq!(
1648 values::<TrashMode>(),
1649 ["list", "restore", "delete_permanently"]
1650 );
1651 assert_eq!(values::<RemovedBy>(), ["author", "operator", "moderation"]);
1652 assert_eq!(values::<ContentKind>(), ["post", "comment"]);
1653 }
1654
1655 #[cfg(feature = "schemars")]
1658 #[test]
1659 fn obligation_enum_schemas_are_strict_safe() {
1660 fn values<T: schemars::JsonSchema>() -> Vec<String> {
1661 assert!(T::inline_schema());
1662 let value = crate::responses::inline_schema_for::<T>();
1663 assert_eq!(
1664 crate::tools::strict_schema_violations(&value),
1665 Vec::<String>::new()
1666 );
1667 value["enum"]
1668 .as_array()
1669 .unwrap_or_else(|| panic!("a flat `enum`: {value}"))
1670 .iter()
1671 .map(|v| v.as_str().unwrap().to_owned())
1672 .collect()
1673 }
1674 assert_eq!(
1675 values::<ObligationKind>(),
1676 [
1677 "carry_forward",
1678 "ratification",
1679 "review",
1680 "referral",
1681 "reveal",
1682 "task"
1683 ]
1684 );
1685 assert_eq!(values::<OwedBy>(), ["steward", "staff", "council"]);
1686 assert_eq!(
1687 values::<ObligationStatus>(),
1688 ["open", "lapsed", "discharged", "withdrawn"]
1689 );
1690 assert_eq!(
1691 values::<CalendarEventKind>(),
1692 ["sitting", "special_sitting"]
1693 );
1694 }
1695
1696 #[test]
1697 fn trash_enum_wire_values() {
1698 assert_eq!(DeletedBy::Operator.to_string(), "operator");
1699 assert_eq!(
1700 "delete_permanently".parse::<TrashMode>().unwrap(),
1701 TrashMode::DeletePermanently
1702 );
1703 assert_eq!(TrashMode::default(), TrashMode::List);
1704 assert_eq!(RemovedBy::from(DeletedBy::Author), RemovedBy::Author);
1705 assert_eq!(ContentKind::Comment.to_string(), "comment");
1706 }
1707
1708 #[test]
1711 fn unknown_trash_causes_parse() {
1712 assert_eq!(
1713 serde_json::from_str::<RemovedBy>(r#""council""#).unwrap(),
1714 RemovedBy::Unknown
1715 );
1716 assert_eq!(RemovedBy::Unknown.placeholder(), "[removed]");
1717 assert_eq!(
1718 serde_json::from_str::<DeletedBy>(r#""council""#).unwrap(),
1719 DeletedBy::Unknown
1720 );
1721 assert_eq!(RemovedBy::from(DeletedBy::Unknown), RemovedBy::Unknown);
1722 }
1723
1724 #[test]
1725 fn proposal_category_round_trip() {
1726 for cat in [
1727 ProposalCategory::Routine,
1728 ProposalCategory::Policy,
1729 ProposalCategory::Constitutional,
1730 ProposalCategory::Emergency,
1731 ] {
1732 let json = serde_json::to_string(&cat).unwrap();
1733 let back: ProposalCategory = serde_json::from_str(&json).unwrap();
1734 assert_eq!(cat, back);
1735 }
1736 }
1737
1738 #[test]
1741 fn governance_amendment_and_key_wire_values() {
1742 assert_eq!(GovernanceLogEntryType::Amendment.to_string(), "amendment");
1743 assert_eq!(
1744 GovernanceLogEntryType::KeyRotation.to_string(),
1745 "key_rotation"
1746 );
1747 assert_eq!(
1748 AmendmentKind::NonPrecedential.to_string(),
1749 "non_precedential"
1750 );
1751 assert_eq!(AmendmentKind::Reattested.to_string(), "reattested");
1752 assert_eq!(AmendmentKind::Revision.to_string(), "revision");
1753 assert_eq!(RecordVersion::default(), RecordVersion::Latest);
1754 assert_eq!(RecordVersion::Original.to_string(), "original");
1755 assert_eq!(
1756 "latest".parse::<RecordVersion>().unwrap(),
1757 RecordVersion::Latest
1758 );
1759 assert_eq!(
1760 "superseded".parse::<AmendmentKind>().unwrap(),
1761 AmendmentKind::Superseded
1762 );
1763 assert_eq!(Standing::default(), Standing::InForce);
1764 assert_eq!(Standing::InForce.to_string(), "in_force");
1765 assert_eq!(
1766 "compromised".parse::<KeyStatus>().unwrap(),
1767 KeyStatus::Compromised
1768 );
1769 assert_eq!(KeyStatus::Retired.to_string(), "retired");
1770 }
1771
1772 #[test]
1775 fn obligation_and_calendar_wire_values() {
1776 assert_eq!(
1777 GovernanceLogEntryType::Obligation.to_string(),
1778 "obligation"
1779 );
1780 let kinds: Vec<String> =
1781 AmendmentKind::OBLIGATION.map(|k| k.to_string()).to_vec();
1782 assert_eq!(
1783 kinds,
1784 [
1785 "planned",
1786 "discharged",
1787 "lapsed",
1788 "rescheduled",
1789 "withdrawn"
1790 ]
1791 );
1792 assert!(AmendmentKind::Lapsed.is_obligation());
1793 assert!(!AmendmentKind::Revision.is_obligation());
1794 for (kind, wire) in [
1795 (ObligationKind::CarryForward, "carry_forward"),
1796 (ObligationKind::Ratification, "ratification"),
1797 (ObligationKind::Review, "review"),
1798 (ObligationKind::Referral, "referral"),
1799 (ObligationKind::Reveal, "reveal"),
1800 (ObligationKind::Task, "task"),
1801 ] {
1802 assert_eq!(kind.to_string(), wire);
1803 assert_eq!(wire.parse::<ObligationKind>().unwrap(), kind);
1804 }
1805 for (who, wire) in [
1806 (OwedBy::Steward, "steward"),
1807 (OwedBy::Staff, "staff"),
1808 (OwedBy::Council, "council"),
1809 ] {
1810 assert_eq!(who.to_string(), wire);
1811 assert_eq!(wire.parse::<OwedBy>().unwrap(), who);
1812 }
1813 assert_eq!(ObligationStatus::default(), ObligationStatus::Open);
1814 assert_eq!(ObligationStatus::Lapsed.to_string(), "lapsed");
1815 assert!(ObligationStatus::Withdrawn.is_closed());
1816 assert!(!ObligationStatus::Lapsed.is_closed());
1817 assert_eq!(
1818 CalendarEventKind::SpecialSitting.to_string(),
1819 "special_sitting"
1820 );
1821 assert!("festival".parse::<CalendarEventKind>().is_err());
1824 assert_eq!(
1825 "cancelled".parse::<CalendarEventStatus>().unwrap(),
1826 CalendarEventStatus::Cancelled
1827 );
1828 }
1829
1830 #[test]
1832 fn detail_level_wire_names() {
1833 for (level, wire) in [
1834 (DetailLevel::Summary, "summary"),
1835 (DetailLevel::Full, "full"),
1836 (DetailLevel::FullWithAttachments, "full_with_attachments"),
1837 ] {
1838 assert_eq!(serde_json::to_value(level).unwrap(), wire);
1839 assert_eq!(level.to_string(), wire);
1840 assert_eq!(wire.parse::<DetailLevel>().unwrap(), level);
1841 }
1842 }
1843
1844 #[cfg(feature = "schemars")]
1849 #[test]
1850 fn enum_json_schema_is_inlined() {
1851 use schemars::JsonSchema;
1852
1853 assert!(<TargetType as JsonSchema>::inline_schema());
1854 assert!(<FeedSort as JsonSchema>::inline_schema());
1855 assert!(<ProposalSort as JsonSchema>::inline_schema());
1856 assert!(<DetailLevel as JsonSchema>::inline_schema());
1857 assert!(<RecordVersion as JsonSchema>::inline_schema());
1858 assert!(<SearchMode as JsonSchema>::inline_schema());
1859 assert!(<ProposalCategory as JsonSchema>::inline_schema());
1860 assert!(<GovernanceLogEntryType as JsonSchema>::inline_schema());
1861 assert!(<AmendmentKind as JsonSchema>::inline_schema());
1862 assert!(<Standing as JsonSchema>::inline_schema());
1863 assert!(<CitationRelation as JsonSchema>::inline_schema());
1864 assert!(<KeyStatus as JsonSchema>::inline_schema());
1865 assert!(<OAuthScope as JsonSchema>::inline_schema());
1866 assert!(<ModerationTargetType as JsonSchema>::inline_schema());
1867 assert!(<ModerationTier as JsonSchema>::inline_schema());
1868 assert!(<ObligationKind as JsonSchema>::inline_schema());
1869 assert!(<OwedBy as JsonSchema>::inline_schema());
1870 assert!(<ObligationStatus as JsonSchema>::inline_schema());
1871 assert!(<CalendarEventKind as JsonSchema>::inline_schema());
1872 assert!(<CalendarEventStatus as JsonSchema>::inline_schema());
1873
1874 #[derive(schemars::JsonSchema)]
1875 #[allow(dead_code)]
1876 struct Container {
1877 target_type: TargetType,
1878 sort: Option<FeedSort>,
1879 proposal_sort: Option<ProposalSort>,
1880 category: Option<ProposalCategory>,
1881 detail: Option<DetailLevel>,
1882 version: Option<RecordVersion>,
1883 search_mode: Option<SearchMode>,
1884 }
1885
1886 let schema = schemars::schema_for!(Container);
1887 let value = serde_json::to_value(&schema).unwrap();
1888 let blob = value.to_string();
1889
1890 assert!(
1891 value.get("$defs").is_none(),
1892 "no $defs should be emitted for enum-only container; got schema: {value}"
1893 );
1894 assert!(
1895 !blob.contains("$ref"),
1896 "enum container schema must contain no $ref anywhere; got: {value}"
1897 );
1898
1899 let target_type_enum = value["properties"]["target_type"]["enum"]
1901 .as_array()
1902 .expect("target_type should have inline `enum` array");
1903 assert!(
1904 target_type_enum
1905 .contains(&serde_json::Value::String("post".into()))
1906 );
1907 assert!(
1908 target_type_enum
1909 .contains(&serde_json::Value::String("comment".into()))
1910 );
1911 }
1912
1913 #[cfg(feature = "schemars")]
1919 #[test]
1920 fn search_mode_schema_is_ref_free() {
1921 use schemars::JsonSchema;
1922
1923 assert!(<SearchMode as JsonSchema>::inline_schema());
1924
1925 let schema = schemars::schema_for!(SearchMode);
1926 let value = serde_json::to_value(&schema).unwrap();
1927 let blob = value.to_string();
1928 assert!(value.get("$defs").is_none(), "no $defs: {value}");
1929 assert!(!blob.contains("$ref"), "no $ref: {value}");
1930
1931 let variants = value["oneOf"]
1937 .as_array()
1938 .expect("SearchMode should have an inline `oneOf` array");
1939 let consts: Vec<&str> = variants
1940 .iter()
1941 .filter_map(|v| v["const"].as_str())
1942 .collect();
1943 assert!(consts.contains(&"keyword"), "{value}");
1944 assert!(consts.contains(&"semantic"), "{value}");
1945 }
1946}