Skip to main content

sew_proto/
examples.rs

1//! Example values for every top-level wire type.
2//!
3//! Ids are realistic single-node ids made at 2026-09-27T12:00:00.123Z (ms since the Sew epoch
4//! `23_284_800_123`, node 0) with distinct sequence numbers, so `ID_MESSAGE` is
5//! `48831765147549701` (seq 5). The `full` case sets every optional field and fills every list;
6//! `min` sets only the required fields.
7
8use serde_json::{Map, Value, json};
9
10use crate::addr::{Addr, Handle, Slug};
11use crate::api::auth::*;
12use crate::api::channels::*;
13use crate::api::files::*;
14use crate::api::members::*;
15use crate::api::messages::*;
16use crate::api::resolve::*;
17use crate::api::spaces::*;
18use crate::audit::*;
19use crate::changes::*;
20use crate::error::*;
21use crate::external_id::ExternalId;
22use crate::gateway::client::*;
23use crate::gateway::events::*;
24use crate::gateway::server::*;
25use crate::gateway::*;
26use crate::http::*;
27use crate::id::Id;
28use crate::mgmt::local::*;
29use crate::mgmt::*;
30use crate::perms::{self, Perms};
31use crate::policy::*;
32use crate::registry::Example;
33use crate::time::Timestamp;
34use crate::when::When;
35
36// Spaces, categories, channels, membership, DMs.
37mod spaces;
38// Messaging.
39mod messaging;
40// Roles, overwrites, moderation.
41mod roles;
42// The audit chain check and export requests over mgmt.
43mod ops;
44// People, presence, groups.
45mod people;
46// Emoji, previews, GIFs, secrets.
47mod media;
48// Retention, legal holds, content_vanished.
49mod retention;
50// Drafts, saved, scheduled, reminders, polls, bookmarks.
51mod extras;
52// Read state, changes and sync types.
53mod read_receipts;
54mod read_state;
55// Voice room notifications: the room start and invites.
56mod voice_notify;
57// Search.
58mod search;
59// Guest conversion and the guest list.
60mod guests;
61// Notifications, the email digest.
62mod notify;
63// Compliance flag, audit API, exports, the archive records.
64mod compliance;
65// Voice types (voice states, joins, moderation, voice dispatches, status).
66mod voice;
67// DM call and media policy types (calls, rings, summaries, `status.voice` media).
68mod calls;
69// Call key types (the key wire, devices, READY `call_keys`).
70mod call_keys;
71// Recording types (recordings, consent, summaries, turns, audio, downloads).
72mod recording;
73// Meeting types (meetings, attendees, `meet/init`).
74mod meetings;
75// Link and link-guest types (links, peek, redeem, resolve).
76mod meeting_links;
77// Lobby types (entries, knock, admission, the guest-shaped meeting_updated).
78mod meeting_lobby;
79// Host-control bodies (lock, remove).
80mod meeting_controls;
81// Meeting people (names for everyone in a meeting channel).
82mod meeting_people;
83// Ban types (ban request, bans, the ban page).
84mod space_bans;
85// Member-channels sync types.
86mod member_channels;
87// Voice over mgmt.
88mod mgmt_voice;
89// Recording in Apps over mgmt.
90mod mgmt_recordings;
91
92const fn id(seq: u64) -> Id {
93    // 23_284_800_123 << 21 = 48_831_765_147_549_696
94    Id::new_const(48_831_765_147_549_696 + seq)
95}
96
97const ID_SPACE: Id = id(1);
98const ID_CHANNEL: Id = id(2);
99const ID_ME: Id = id(3);
100const ID_BOB: Id = id(4);
101const ID_MESSAGE: Id = id(5);
102const ID_CATEGORY: Id = id(6);
103const ID_ROLE: Id = id(7);
104const ID_REPLY: Id = id(8);
105const ID_ATTACHMENT: Id = id(9);
106const ID_JOB: Id = id(10);
107const ID_INSTALL: Id = id(11);
108const ID_AUDIT: Id = id(12);
109const ID_EMOJI: Id = id(13);
110const ID_GROUP: Id = id(14);
111const ID_DM: Id = id(15);
112const ID_CAROL: Id = id(16);
113const ID_OTHER_CHANNEL: Id = id(17);
114
115/// 2026-09-27T12:00:00.123Z.
116const T0_MS: u64 = 1_790_510_400_123;
117
118fn t(offset_ms: u64) -> Timestamp {
119    Timestamp::from_unix_ms_saturating(T0_MS + offset_ms)
120}
121
122fn slug(s: &str) -> Slug {
123    match Slug::new(s) {
124        Ok(v) => v,
125        Err(e) => panic!("example slug {s:?}: {e}"),
126    }
127}
128
129fn handle(s: &str) -> Handle {
130    match Handle::new(s) {
131        Ok(v) => v,
132        Err(e) => panic!("example handle {s:?}: {e}"),
133    }
134}
135
136fn ext(s: &str) -> ExternalId {
137    match s.parse() {
138        Ok(v) => v,
139        Err(e) => panic!("example external id {s:?}: {e}"),
140    }
141}
142
143fn addr(s: &str) -> Addr {
144    match s.parse() {
145        Ok(v) => v,
146        Err(e) => panic!("example addr {s:?}: {e}"),
147    }
148}
149
150const PRINCIPAL: &str = "k2:principal:0f8fad5b-d9cb-469f-a165-70867728950e";
151const WORKSPACE: &str = "k2:workspace:7c9e6679-7425-40de-944b-e07fc1f90ae7";
152/// A K2 Connect user (`k2:connect:<uuid>`).
153const CONNECT_USER: &str = "k2:connect:3d6f0a1e-5b2c-4e8d-9f7a-1c2b3d4e5f60";
154const PASS: &str = "eyJhbGciOiJFUzI1NiIsImtpZCI6IjAxMjM0NTY3ODlhYmNkZWYiLCJ0eXAiOiJrMi1jaGF0LXBhc3Mrand0In0.eyJzdWIiOiJrMjpwcmluY2lwYWw6MGY4ZmFkNWIifQ.c2lnbmF0dXJl";
155
156fn session_token() -> String {
157    format!(
158        "sews_example-selector-00001.example-secret-{}",
159        "x".repeat(28)
160    )
161}
162
163fn ticket() -> String {
164    format!("sewtk_example-ticket-{}", "y".repeat(28))
165}
166
167fn obj(v: Value) -> Map<String, Value> {
168    match v {
169        Value::Object(m) => m,
170        other => panic!("example details must be an object, got {other}"),
171    }
172}
173
174// ---------------------------------------------------------------- api/auth
175
176impl Example for K2PassRequest {
177    fn examples() -> Vec<(&'static str, Self)> {
178        vec![("full", K2PassRequest { pass: PASS.into() })]
179    }
180}
181
182impl Example for RenewRequest {
183    fn examples() -> Vec<(&'static str, Self)> {
184        vec![("full", RenewRequest { pass: PASS.into() })]
185    }
186}
187
188impl Example for LoginRequest {
189    fn examples() -> Vec<(&'static str, Self)> {
190        vec![(
191            "full",
192            LoginRequest {
193                username: handle("morgan"),
194                password: "correct horse battery staple".into(),
195            },
196        )]
197    }
198}
199
200impl Example for PasswordSetRequest {
201    fn examples() -> Vec<(&'static str, Self)> {
202        vec![(
203            "full",
204            PasswordSetRequest {
205                token: format!("sewpw_example-setup-token-{}", "z".repeat(24)),
206                password: "correct horse battery staple".into(),
207            },
208        )]
209    }
210}
211
212impl Example for SessionResponse {
213    fn examples() -> Vec<(&'static str, Self)> {
214        vec![(
215            "full",
216            SessionResponse {
217                token: session_token(),
218                expires_at: t(3_600_000),
219                member: member_min(),
220            },
221        )]
222    }
223}
224
225impl Example for GatewayTicketRequest {
226    fn examples() -> Vec<(&'static str, Self)> {
227        vec![
228            (
229                "full",
230                GatewayTicketRequest {
231                    origin: Some("wss://jobs.example.com".into()),
232                },
233            ),
234            ("min", GatewayTicketRequest::default()),
235        ]
236    }
237}
238
239impl Example for GatewayTicketResponse {
240    fn examples() -> Vec<(&'static str, Self)> {
241        vec![(
242            "full",
243            GatewayTicketResponse {
244                ticket: ticket(),
245                url: "wss://chat.example.com/api/v1/gateway?v=1&encoding=json".into(),
246                expires_in_ms: 30_000,
247            },
248        )]
249    }
250}
251
252// ---------------------------------------------------------------- api/members
253
254fn member_full() -> Member {
255    Member {
256        id: ID_CAROL,
257        kind: MemberKind::Agent,
258        agent_kind: Some(AgentKind::Assistant),
259        assistant_of: Some(ID_ME),
260        install_role: InstallRole::Member,
261        username: handle("morgan-assistant"),
262        display_name: "Morgan's assistant".into(),
263        title: Some("Assistant".into()),
264        pronouns: Some("it/its".into()),
265        avatar_url: Some("/api/v1/avatars/48831765147549712?exp=1790514000&sig=c2ln".into()),
266        deactivated: false,
267        created_at: t(0),
268        email: Some("assistant@example.com".into()),
269        compliance: Some(false),
270        avatar_thumb_url: Some(
271            "/api/v1/avatars/48831765147549712/48831765147549740/64?exp=1791158400&sig=c2ln".into(),
272        ),
273        timezone: Some("America/New_York".into()),
274        status: Some(crate::api::people::MemberStatus {
275            text: Some("In a meeting".into()),
276            emoji: Some("📅".into()),
277            expires_at: Some(t(1_800_000)),
278        }),
279        profile_rev: 7,
280        custom_fields: Some(vec![crate::api::people::ProfileFieldValue {
281            field_id: id(41),
282            key: "team".into(),
283            value: "Platform".into(),
284        }]),
285        managed_fields: Some(vec![
286            "display_name".into(),
287            "username".into(),
288            "email".into(),
289            "title".into(),
290            "pronouns".into(),
291        ]),
292        external_id: Some("k2:principal:0b5e7c1a-3f2d-4e8b-9a61-2c4d8f0e1b37".into()),
293        erased: false,
294    }
295}
296
297/// An erased member as others see it.
298fn member_erased() -> Member {
299    Member {
300        id: ID_BOB,
301        username: handle("erased-48831765147549700"),
302        display_name: "Deleted user".into(),
303        deactivated: true,
304        install_role: InstallRole::Member,
305        erased: true,
306        ..member_min()
307    }
308}
309
310fn member_min() -> Member {
311    Member {
312        id: ID_ME,
313        kind: MemberKind::Person,
314        agent_kind: None,
315        assistant_of: None,
316        install_role: InstallRole::Owner,
317        username: handle("morgan"),
318        display_name: "Morgan".into(),
319        title: None,
320        pronouns: None,
321        avatar_url: None,
322        deactivated: false,
323        created_at: t(0),
324        email: None,
325        compliance: None,
326        avatar_thumb_url: None,
327        timezone: None,
328        status: None,
329        profile_rev: 0,
330        custom_fields: None,
331        managed_fields: None,
332        external_id: None,
333        erased: false,
334    }
335}
336
337impl Example for Member {
338    fn examples() -> Vec<(&'static str, Self)> {
339        vec![
340            ("full", member_full()),
341            ("full_erased", member_erased()),
342            ("min", member_min()),
343        ]
344    }
345}
346
347impl Example for Page<Member> {
348    fn examples() -> Vec<(&'static str, Self)> {
349        vec![(
350            "full",
351            Page {
352                items: vec![member_min(), member_full()],
353                has_more: true,
354            },
355        )]
356    }
357}
358
359// ---------------------------------------------------------------- api/spaces
360
361fn space_min() -> Space {
362    Space {
363        id: ID_SPACE,
364        slug: slug("acme-eng"),
365        name: "Acme Engineering".into(),
366        icon_url: None,
367        icon_thumb_url: None,
368        owner_id: ID_ME,
369        member_count: 42,
370        created_at: t(0),
371        join_policy: SpaceJoinPolicy::Invite,
372        my_perms: None,
373        default_channel_ids: vec![],
374        description: None,
375        rules_channel_id: None,
376        welcome_channel_id: None,
377        app_id: None,
378        app_display_name: None,
379        participant_app_ids: vec![],
380        orphaned_from: None,
381        hidden: false,
382        private: false,
383        governance: SpaceGovernance::Sew,
384    }
385}
386
387impl Example for Space {
388    fn examples() -> Vec<(&'static str, Self)> {
389        let full = Space {
390            icon_url: Some("/api/v1/space-icons/48831765147549697/48831765147549716/512?exp=1791158400&sig=c2ln".into()),
391            icon_thumb_url: Some("/api/v1/space-icons/48831765147549697/48831765147549716/64?exp=1791158400&sig=c2ln".into()),
392            // A private Space is invite-only.
393            join_policy: SpaceJoinPolicy::Invite,
394            my_perms: Some(perms::DEFAULT_EVERYONE),
395            default_channel_ids: vec![ID_CHANNEL],
396            description: Some("Where Acme's engineers talk.".into()),
397            rules_channel_id: Some(ID_OTHER_CHANNEL),
398            welcome_channel_id: Some(ID_CHANNEL),
399            app_id: Some("atrium".into()),
400            app_display_name: Some("Atrium".into()),
401            participant_app_ids: vec!["jobs".into()],
402            orphaned_from: Some("atrium".into()),
403            hidden: true,
404            private: true,
405            governance: SpaceGovernance::App,
406            ..space_min()
407        };
408        vec![("full", full), ("min", space_min())]
409    }
410}
411
412impl Example for CreateSpaceRequest {
413    fn examples() -> Vec<(&'static str, Self)> {
414        vec![
415            (
416                "full",
417                CreateSpaceRequest {
418                    slug: slug("acme-eng"),
419                    name: "Acme Engineering".into(),
420                    join_policy: Some(SpaceJoinPolicy::Open),
421                },
422            ),
423            (
424                "min",
425                CreateSpaceRequest {
426                    slug: slug("acme-eng"),
427                    name: "Acme Engineering".into(),
428                    join_policy: None,
429                },
430            ),
431        ]
432    }
433}
434
435impl Example for UpdateSpaceRequest {
436    fn examples() -> Vec<(&'static str, Self)> {
437        vec![
438            (
439                "full",
440                UpdateSpaceRequest {
441                    slug: Some(slug("acme-platform")),
442                    name: Some("Acme Platform".into()),
443                    join_policy: Some(SpaceJoinPolicy::Invite),
444                    default_channel_ids: Some(vec![ID_CHANNEL]),
445                    description: Patch::Set("Where Acme's engineers talk.".into()),
446                    rules_channel_id: Patch::Set(ID_OTHER_CHANNEL),
447                    welcome_channel_id: Patch::Clear,
448                    private: Some(true),
449                },
450            ),
451            ("min", UpdateSpaceRequest::default()),
452        ]
453    }
454}
455
456pub(super) fn overwrite() -> Overwrite {
457    Overwrite {
458        target_kind: OverwriteTarget::Role,
459        target_id: ID_SPACE,
460        allow: Perms::SEND_IN_THREADS,
461        deny: Perms::SEND_MESSAGES,
462    }
463}
464
465impl Example for Category {
466    fn examples() -> Vec<(&'static str, Self)> {
467        vec![(
468            "full",
469            Category {
470                id: ID_CATEGORY,
471                space_id: ID_SPACE,
472                name: "Engineering".into(),
473                position: 1,
474                overwrites: vec![overwrite()],
475            },
476        )]
477    }
478}
479
480impl Example for CreateCategoryRequest {
481    fn examples() -> Vec<(&'static str, Self)> {
482        vec![
483            (
484                "full",
485                CreateCategoryRequest {
486                    name: "Engineering".into(),
487                    position: Some(1),
488                },
489            ),
490            (
491                "min",
492                CreateCategoryRequest {
493                    name: "Engineering".into(),
494                    position: None,
495                },
496            ),
497        ]
498    }
499}
500
501impl Example for UpdateCategoryRequest {
502    fn examples() -> Vec<(&'static str, Self)> {
503        vec![
504            (
505                "full",
506                UpdateCategoryRequest {
507                    name: Some("Platform".into()),
508                    position: Some(2),
509                },
510            ),
511            ("min", UpdateCategoryRequest::default()),
512        ]
513    }
514}
515
516pub(super) fn role_min() -> Role {
517    Role {
518        id: ID_SPACE,
519        space_id: ID_SPACE,
520        name: "@everyone".into(),
521        color: None,
522        position: 0,
523        perms: perms::DEFAULT_EVERYONE,
524        mentionable: false,
525        is_everyone: true,
526        hoist: false,
527        managed: None,
528    }
529}
530
531impl Example for Role {
532    fn examples() -> Vec<(&'static str, Self)> {
533        let full = Role {
534            id: ID_ROLE,
535            space_id: ID_SPACE,
536            name: "Moderators".into(),
537            color: Some(0x3b_82_f6),
538            position: 3,
539            perms: Perms::MANAGE_MESSAGES | Perms::PIN_MESSAGES | Perms::TIMEOUT_MEMBERS,
540            mentionable: true,
541            is_everyone: false,
542            hoist: true,
543            managed: Some(SpaceLevel::Moderator),
544        };
545        vec![("full", full), ("min", role_min())]
546    }
547}
548
549// ---------------------------------------------------------------- api/channels
550
551fn channel_full() -> Channel {
552    Channel {
553        id: ID_CHANNEL,
554        space_id: Some(ID_SPACE),
555        category_id: Some(ID_CATEGORY),
556        kind: ChannelType::Text,
557        visibility: Visibility::Public,
558        slug: Some(slug("deploys")),
559        name: Some("deploys".into()),
560        topic: Some("Release train status".into()),
561        purpose: Some("Coordinate deploys".into()),
562        position: 4,
563        synced: true,
564        archived_at: Some(t(86_400_000)),
565        head_seq: 1_024,
566        last_message_id: Some(ID_MESSAGE),
567        dm_member_ids: vec![ID_ME, ID_BOB],
568        my_perms: Some(perms::DEFAULT_EVERYONE),
569        created_at: t(0),
570        member_count: 12,
571        created_by: Some(ID_ME),
572        slow_mode_s: 30,
573        retention_days: Some(90),
574        file_retention_days: Some(30),
575        has_guests: true,
576        assistant_reader_ids: vec![ID_CAROL],
577        user_limit: 0,
578        recording_auto: false,
579        recording_audio_days: None,
580        recording_require_consent: None,
581        recording_required: None,
582        recording_rule: crate::recording::RecordingRule::None,
583        meeting: None,
584        closing: false,
585        members_can_leave: true,
586    }
587}
588
589/// A voice channel with a user limit.
590fn channel_voice() -> Channel {
591    Channel {
592        kind: ChannelType::Voice,
593        slug: Some(slug("lounge")),
594        name: Some("lounge".into()),
595        archived_at: None,
596        dm_member_ids: vec![],
597        assistant_reader_ids: vec![],
598        user_limit: 25,
599        recording_auto: true,
600        recording_audio_days: Some(30),
601        recording_require_consent: Some(true),
602        recording_required: Some(true),
603        recording_rule: crate::recording::RecordingRule::Auto,
604        meeting: Some(crate::api::meetings::ChannelMeeting { id: id(600) }),
605        closing: true,
606        ..channel_full()
607    }
608}
609
610fn channel_min() -> Channel {
611    Channel {
612        id: ID_DM,
613        space_id: None,
614        category_id: None,
615        kind: ChannelType::Dm,
616        visibility: Visibility::Private,
617        slug: None,
618        name: None,
619        topic: None,
620        purpose: None,
621        position: 0,
622        synced: false,
623        archived_at: None,
624        head_seq: 0,
625        last_message_id: None,
626        dm_member_ids: vec![],
627        my_perms: None,
628        created_at: t(0),
629        member_count: 0,
630        created_by: None,
631        slow_mode_s: 0,
632        retention_days: None,
633        file_retention_days: None,
634        has_guests: false,
635        assistant_reader_ids: vec![],
636        user_limit: 0,
637        recording_auto: false,
638        recording_audio_days: None,
639        recording_require_consent: None,
640        recording_required: None,
641        recording_rule: crate::recording::RecordingRule::None,
642        meeting: None,
643        closing: false,
644        members_can_leave: false,
645    }
646}
647
648impl Example for Channel {
649    fn examples() -> Vec<(&'static str, Self)> {
650        vec![
651            ("full", channel_full()),
652            ("full_voice", channel_voice()),
653            ("min", channel_min()),
654        ]
655    }
656}
657
658impl Example for CreateChannelRequest {
659    fn examples() -> Vec<(&'static str, Self)> {
660        let min = CreateChannelRequest {
661            slug: slug("deploys"),
662            name: "deploys".into(),
663            kind: ChannelType::Text,
664            visibility: Visibility::Public,
665            category_id: None,
666            topic: None,
667            purpose: None,
668            position: None,
669            member_ids: vec![],
670            user_limit: None,
671        };
672        let voice = CreateChannelRequest {
673            slug: slug("lounge"),
674            name: "lounge".into(),
675            kind: ChannelType::Voice,
676            user_limit: Some(25),
677            ..min.clone()
678        };
679        let full = CreateChannelRequest {
680            kind: ChannelType::Announcement,
681            visibility: Visibility::Private,
682            category_id: Some(ID_CATEGORY),
683            topic: Some("Release train status".into()),
684            purpose: Some("Coordinate deploys".into()),
685            position: Some(0),
686            member_ids: vec![ID_BOB, ID_CAROL],
687            ..min.clone()
688        };
689        vec![("full", full), ("full_voice", voice), ("min", min)]
690    }
691}
692
693impl Example for UpdateChannelRequest {
694    fn examples() -> Vec<(&'static str, Self)> {
695        vec![
696            (
697                "full",
698                UpdateChannelRequest {
699                    slug: Some(slug("releases")),
700                    name: Some("releases".into()),
701                    topic: Patch::Set("Release status".into()),
702                    purpose: Patch::Set("Ship it".into()),
703                    category_id: Patch::Set(ID_CATEGORY),
704                    position: Some(2),
705                    user_limit: Some(10),
706                    recording_auto: Some(true),
707                    recording_audio_days: Patch::Set(30),
708                    recording_require_consent: Patch::Clear,
709                    recording_required: Patch::Set(true),
710                },
711            ),
712            ("min", UpdateChannelRequest::default()),
713            (
714                "clear",
715                UpdateChannelRequest {
716                    topic: Patch::Clear,
717                    category_id: Patch::Clear,
718                    ..UpdateChannelRequest::default()
719                },
720            ),
721        ]
722    }
723}
724
725fn channel_member() -> ChannelMember {
726    ChannelMember {
727        channel_id: ID_CHANNEL,
728        member_id: ID_BOB,
729        joined_at: t(0),
730    }
731}
732
733impl Example for ChannelMember {
734    fn examples() -> Vec<(&'static str, Self)> {
735        vec![("full", channel_member())]
736    }
737}
738
739impl Example for Page<ChannelMember> {
740    fn examples() -> Vec<(&'static str, Self)> {
741        vec![(
742            "full",
743            Page {
744                items: vec![channel_member()],
745                has_more: false,
746            },
747        )]
748    }
749}
750
751impl Example for AddChannelMembersRequest {
752    fn examples() -> Vec<(&'static str, Self)> {
753        vec![(
754            "full",
755            AddChannelMembersRequest {
756                member_ids: vec![ID_BOB, ID_CAROL],
757            },
758        )]
759    }
760}
761
762impl Example for ChannelTypingRequest {
763    fn examples() -> Vec<(&'static str, Self)> {
764        vec![
765            (
766                "full",
767                ChannelTypingRequest {
768                    thread_id: Some(ID_MESSAGE),
769                },
770            ),
771            ("min", ChannelTypingRequest::default()),
772        ]
773    }
774}
775
776impl Example for RemoveChannelMemberRequest {
777    fn examples() -> Vec<(&'static str, Self)> {
778        vec![("full", RemoveChannelMemberRequest { member_id: ID_BOB })]
779    }
780}
781
782impl Example for OpenDmRequest {
783    fn examples() -> Vec<(&'static str, Self)> {
784        vec![
785            (
786                "full",
787                OpenDmRequest {
788                    member_ids: vec![ID_BOB],
789                    usernames: vec![handle("carol")],
790                },
791            ),
792            // By handle only.
793            (
794                "usernames",
795                OpenDmRequest {
796                    member_ids: vec![],
797                    usernames: vec![handle("bob")],
798                },
799            ),
800        ]
801    }
802}
803
804// ---------------------------------------------------------------- api/resolve
805
806impl Example for ResolveQuery {
807    fn examples() -> Vec<(&'static str, Self)> {
808        vec![
809            (
810                "full",
811                ResolveQuery {
812                    addr: addr("acme-eng/#deploys/48831765147549701"),
813                },
814            ),
815            (
816                "dm",
817                ResolveQuery {
818                    addr: addr("dm/@morgan"),
819                },
820            ),
821        ]
822    }
823}
824
825impl Example for ResolveResponse {
826    fn examples() -> Vec<(&'static str, Self)> {
827        vec![
828            (
829                "full",
830                ResolveResponse {
831                    space_id: Some(ID_SPACE),
832                    channel_id: ID_CHANNEL,
833                    thread_id: Some(ID_MESSAGE),
834                },
835            ),
836            (
837                "min",
838                ResolveResponse {
839                    space_id: None,
840                    channel_id: ID_DM,
841                    thread_id: None,
842                },
843            ),
844        ]
845    }
846}
847
848// ---------------------------------------------------------------- api/messages
849
850fn thread_full() -> ThreadSummary {
851    ThreadSummary {
852        root_id: ID_MESSAGE,
853        channel_id: ID_CHANNEL,
854        reply_count: 3,
855        last_reply_id: Some(ID_REPLY),
856        last_reply_at: Some(t(60_000)),
857        following: true,
858        seq: Some(1_025),
859    }
860}
861
862fn thread_min() -> ThreadSummary {
863    ThreadSummary {
864        root_id: ID_MESSAGE,
865        channel_id: ID_CHANNEL,
866        reply_count: 0,
867        last_reply_id: None,
868        last_reply_at: None,
869        following: false,
870        seq: None,
871    }
872}
873
874#[allow(deprecated)]
875fn message_full() -> Message {
876    Message {
877        id: ID_REPLY,
878        channel_id: ID_CHANNEL,
879        author_id: ID_CAROL,
880        on_behalf_of: Some(ID_ME),
881        on_behalf_approval: Some(OnBehalfApproval {
882            state: OnBehalfApprovalState::Approved,
883            by: Some(ID_ME),
884            at: Some(t(180_000)),
885        }),
886        body: "Deploy finished, <@48831765147549700> please verify.".into(),
887        nonce: Some(Nonce::new("c1-7f3a")),
888        thread_root_id: Some(ID_MESSAGE),
889        also_in_channel: true,
890        reference: Some(MessageReference {
891            kind: ReferenceKind::Reply,
892            message_id: ID_MESSAGE,
893            channel_id: ID_CHANNEL,
894        }),
895        forwarded: Some(ForwardedMessage {
896            message_id: ID_MESSAGE,
897            channel_id: ID_OTHER_CHANNEL,
898            author_id: ID_BOB,
899            body: "Deploying 0.41.0 now.".into(),
900            created_at: t(0),
901        }),
902        mentions: MentionTargets {
903            members: vec![ID_BOB],
904            roles: vec![ID_ROLE],
905            groups: vec![ID_GROUP],
906            channel: true,
907            here: true,
908        },
909        reactions: vec![
910            ReactionSummary {
911                emoji: Emoji::Unicode {
912                    value: "👍".into()
913                },
914                count: 2,
915                me: true,
916            },
917            ReactionSummary {
918                emoji: Emoji::Custom {
919                    id: ID_EMOJI,
920                    name: "party".into(),
921                    animated: true,
922                    url: Some(
923                        "/api/v1/emoji-images/48831765147549709/full?exp=1791158400&sig=c2ln"
924                            .into(),
925                    ),
926                    available: true,
927                },
928                count: 1,
929                me: false,
930            },
931        ],
932        attachments: vec![attachment_full()],
933        pinned: true,
934        thread: Some(thread_full()),
935        seq: 1_024,
936        created_at: t(60_000),
937        edited_at: Some(t(120_000)),
938        deleted_at: Some(t(180_000)),
939        deleted_reason: Some(DeletedReason::Erased),
940        previews: vec![media::link_preview_full(), media::link_preview_min()],
941        previews_suppressed: true,
942        emojis: vec![media::emoji_ref_full(), media::emoji_ref_deleted()],
943        poll: Some(extras::poll_full()),
944        mentions_me: true,
945        call: Some(calls::call_summary_full()),
946        recording: Some(recording::recording_summary_full()),
947        transcript: Some(recording::transcript_turn_full()),
948        system: None,
949        // The full summary's transcript is `partial` with gaps.
950        transcript_failure: Some(crate::recording::TranscriptFailure::new(
951            crate::recording::TranscriptFailureCode::AudioNotCaptured,
952        )),
953    }
954}
955
956/// A group DM's rename notice: a system message with an empty body.
957fn message_system() -> Message {
958    let mut m = message_min();
959    m.body = String::new();
960    m.system = Some(MessageKind::GroupDmRenamed {
961        name: Some("Launch crew".into()),
962    });
963    m
964}
965
966#[allow(deprecated)]
967fn message_min() -> Message {
968    Message {
969        id: ID_MESSAGE,
970        channel_id: ID_CHANNEL,
971        author_id: ID_ME,
972        on_behalf_of: None,
973        on_behalf_approval: None,
974        body: "Deploying 0.41.0 now.".into(),
975        nonce: None,
976        thread_root_id: None,
977        also_in_channel: false,
978        reference: None,
979        forwarded: None,
980        mentions: MentionTargets::default(),
981        reactions: vec![],
982        attachments: vec![],
983        pinned: false,
984        thread: None,
985        seq: 1_020,
986        created_at: t(0),
987        edited_at: None,
988        deleted_at: None,
989        deleted_reason: None,
990        previews: vec![],
991        previews_suppressed: false,
992        emojis: vec![],
993        poll: None,
994        mentions_me: false,
995        call: None,
996        recording: None,
997        transcript: None,
998        system: None,
999        transcript_failure: None,
1000    }
1001}
1002
1003impl Example for Message {
1004    fn examples() -> Vec<(&'static str, Self)> {
1005        vec![
1006            ("full", message_full()),
1007            ("full_system", message_system()),
1008            ("min", message_min()),
1009        ]
1010    }
1011}
1012
1013// ---------------------------------------------------------------- api/files
1014
1015fn attachment_full() -> Attachment {
1016    Attachment {
1017        id: ID_ATTACHMENT,
1018        filename: "deploy.png".into(),
1019        content_type: "image/png".into(),
1020        size: 48_213,
1021        url: "/api/v1/files/48831765147549705?exp=1790514000&sig=c2ln".into(),
1022        thumbnail_url: Some("/api/v1/files/48831765147549705/thumb?exp=1790514000&sig=c2ln".into()),
1023        width: Some(1280),
1024        height: Some(720),
1025        kind: FileKind::Image,
1026        inline: true,
1027        animated: false,
1028        media_pending: false,
1029        preview_url: Some("/api/v1/files/48831765147549705/preview?exp=1790514000&sig=c2ln".into()),
1030        poster_url: None,
1031        url_expires_at: Some(t(3_600_000)),
1032    }
1033}
1034
1035fn attachment_min() -> Attachment {
1036    Attachment {
1037        id: ID_ATTACHMENT,
1038        filename: "notes.txt".into(),
1039        content_type: "text/plain".into(),
1040        size: 0,
1041        url: "/api/v1/files/48831765147549705?exp=1790514000&sig=c2ln".into(),
1042        thumbnail_url: None,
1043        width: None,
1044        height: None,
1045        kind: FileKind::Document,
1046        inline: false,
1047        animated: false,
1048        media_pending: false,
1049        preview_url: None,
1050        poster_url: None,
1051        url_expires_at: None,
1052    }
1053}
1054
1055fn attachment_video() -> Attachment {
1056    Attachment {
1057        id: ID_REPLY,
1058        filename: "demo.mp4".into(),
1059        content_type: "video/mp4".into(),
1060        size: 7_340_032,
1061        url: "/api/v1/files/48831765147549704?exp=1790514000&sig=c2ln".into(),
1062        thumbnail_url: Some("/api/v1/files/48831765147549704/thumb?exp=1790514000&sig=c2ln".into()),
1063        width: Some(640),
1064        height: Some(360),
1065        kind: FileKind::Video,
1066        inline: true,
1067        animated: false,
1068        media_pending: false,
1069        preview_url: None,
1070        poster_url: Some("/api/v1/files/48831765147549704/poster?exp=1790514000&sig=c2ln".into()),
1071        url_expires_at: Some(t(3_600_000)),
1072    }
1073}
1074
1075const UPLOAD_URL: &str = "/api/v1/uploads/48831765147549705/data?exp=1790514000&sig=c2ln";
1076
1077impl Example for CreateUploadRequest {
1078    fn examples() -> Vec<(&'static str, Self)> {
1079        vec![
1080            (
1081                "full",
1082                CreateUploadRequest {
1083                    filename: "quarterly report.pdf".into(),
1084                    size: 4_194_304,
1085                    content_type: Some("application/pdf".into()),
1086                },
1087            ),
1088            (
1089                "min",
1090                CreateUploadRequest {
1091                    filename: "notes.txt".into(),
1092                    size: 0,
1093                    content_type: None,
1094                },
1095            ),
1096        ]
1097    }
1098}
1099
1100impl Example for CreateUploadResponse {
1101    fn examples() -> Vec<(&'static str, Self)> {
1102        vec![(
1103            "full",
1104            CreateUploadResponse {
1105                upload_id: ID_ATTACHMENT,
1106                upload_url: UPLOAD_URL.into(),
1107                url_expires_at: t(3_600_000),
1108                chunk_size: 1_048_576,
1109                committed_bytes: 0,
1110                size: 4_194_304,
1111                complete: false,
1112                expires_at: t(86_400_000),
1113            },
1114        )]
1115    }
1116}
1117
1118impl Example for UploadStatus {
1119    fn examples() -> Vec<(&'static str, Self)> {
1120        vec![(
1121            "full",
1122            UploadStatus {
1123                upload_id: ID_ATTACHMENT,
1124                committed_bytes: 3_145_728,
1125                size: 4_194_304,
1126                complete: false,
1127                expires_at: t(86_400_000),
1128            },
1129        )]
1130    }
1131}
1132
1133impl Example for Upload {
1134    fn examples() -> Vec<(&'static str, Self)> {
1135        let min = Upload {
1136            upload_id: ID_ATTACHMENT,
1137            committed_bytes: 1_048_576,
1138            size: 4_194_304,
1139            complete: false,
1140            expires_at: t(86_400_000),
1141            channel_id: ID_CHANNEL,
1142            filename: "quarterly report.pdf".into(),
1143            chunk_size: 1_048_576,
1144            upload_url: UPLOAD_URL.into(),
1145            url_expires_at: t(3_600_000),
1146            content_type: None,
1147            kind: None,
1148            width: None,
1149            height: None,
1150            media_pending: false,
1151            thumbnail_url: None,
1152        };
1153        let full = Upload {
1154            committed_bytes: 48_213,
1155            size: 48_213,
1156            complete: true,
1157            filename: "deploy.png".into(),
1158            content_type: Some("image/png".into()),
1159            kind: Some(FileKind::Image),
1160            width: Some(1280),
1161            height: Some(720),
1162            media_pending: true,
1163            thumbnail_url: Some(
1164                "/api/v1/files/48831765147549705/thumb?exp=1790514000&sig=c2ln".into(),
1165            ),
1166            ..min.clone()
1167        };
1168        vec![("full", full), ("min", min)]
1169    }
1170}
1171
1172impl Example for RemoveAttachmentsRequest {
1173    fn examples() -> Vec<(&'static str, Self)> {
1174        vec![(
1175            "full",
1176            RemoveAttachmentsRequest {
1177                attachment_ids: vec![ID_ATTACHMENT],
1178            },
1179        )]
1180    }
1181}
1182
1183impl Example for FilesQuery {
1184    fn examples() -> Vec<(&'static str, Self)> {
1185        vec![
1186            (
1187                "full",
1188                FilesQuery {
1189                    before: Some(ID_ATTACHMENT),
1190                    after: None,
1191                    around: None,
1192                    limit: Some(50),
1193                    kind: Some(FileKind::Image),
1194                    from: Some(ID_BOB),
1195                },
1196            ),
1197            (
1198                "full_after",
1199                FilesQuery {
1200                    after: Some(ID_ATTACHMENT),
1201                    ..FilesQuery::default()
1202                },
1203            ),
1204            (
1205                "full_around",
1206                FilesQuery {
1207                    around: Some(ID_ATTACHMENT),
1208                    ..FilesQuery::default()
1209                },
1210            ),
1211            ("min", FilesQuery::default()),
1212        ]
1213    }
1214}
1215
1216fn channel_file_full() -> ChannelFile {
1217    ChannelFile {
1218        attachment: attachment_full(),
1219        message_id: ID_REPLY,
1220        channel_id: ID_CHANNEL,
1221        thread_root_id: Some(ID_MESSAGE),
1222        author_id: ID_CAROL,
1223        created_at: t(60_000),
1224    }
1225}
1226
1227impl Example for ChannelFile {
1228    fn examples() -> Vec<(&'static str, Self)> {
1229        vec![
1230            ("full", channel_file_full()),
1231            (
1232                "min",
1233                ChannelFile {
1234                    attachment: attachment_min(),
1235                    message_id: ID_MESSAGE,
1236                    channel_id: ID_CHANNEL,
1237                    thread_root_id: None,
1238                    author_id: ID_BOB,
1239                    created_at: t(0),
1240                },
1241            ),
1242        ]
1243    }
1244}
1245
1246impl Example for Page<ChannelFile> {
1247    fn examples() -> Vec<(&'static str, Self)> {
1248        vec![(
1249            "full",
1250            Page {
1251                items: vec![channel_file_full()],
1252                has_more: true,
1253            },
1254        )]
1255    }
1256}
1257
1258impl Example for AttachmentsUpdated {
1259    fn examples() -> Vec<(&'static str, Self)> {
1260        vec![
1261            (
1262                "full",
1263                AttachmentsUpdated {
1264                    channel_id: ID_CHANNEL,
1265                    message_id: ID_REPLY,
1266                    thread_root_id: Some(ID_MESSAGE),
1267                    attachments: vec![attachment_full(), attachment_video(), attachment_min()],
1268                    seq: 1_026,
1269                },
1270            ),
1271            (
1272                "min",
1273                AttachmentsUpdated {
1274                    channel_id: ID_CHANNEL,
1275                    message_id: ID_MESSAGE,
1276                    thread_root_id: None,
1277                    attachments: Vec::new(),
1278                    seq: 0,
1279                },
1280            ),
1281        ]
1282    }
1283}
1284
1285impl Example for Page<Message> {
1286    fn examples() -> Vec<(&'static str, Self)> {
1287        vec![(
1288            "full",
1289            Page {
1290                items: vec![message_full(), message_min()],
1291                has_more: true,
1292            },
1293        )]
1294    }
1295}
1296
1297fn message_version() -> MessageVersion {
1298    MessageVersion {
1299        id: Some(id(18)),
1300        message_id: ID_MESSAGE,
1301        version: 0,
1302        body: "Deploying 0.40.9 now.".into(),
1303        created_at: t(0),
1304        replaced_at: Some(t(30_000)),
1305    }
1306}
1307
1308impl Example for MessageVersion {
1309    fn examples() -> Vec<(&'static str, Self)> {
1310        vec![("full", message_version())]
1311    }
1312}
1313
1314impl Example for Page<MessageVersion> {
1315    fn examples() -> Vec<(&'static str, Self)> {
1316        vec![(
1317            "full",
1318            Page {
1319                items: vec![message_version()],
1320                has_more: false,
1321            },
1322        )]
1323    }
1324}
1325
1326impl Example for ThreadSummary {
1327    fn examples() -> Vec<(&'static str, Self)> {
1328        vec![("full", thread_full()), ("min", thread_min())]
1329    }
1330}
1331
1332impl Example for CreateMessageRequest {
1333    fn examples() -> Vec<(&'static str, Self)> {
1334        vec![
1335            (
1336                "full",
1337                CreateMessageRequest {
1338                    body: "Looks good to me.".into(),
1339                    nonce: Some(Nonce::new("c1-7f3a")),
1340                    thread_root_id: Some(ID_MESSAGE),
1341                    also_send_to_channel: true,
1342                    reference: Some(ReferenceInput {
1343                        message_id: ID_MESSAGE,
1344                        kind: ReferenceKind::Quote,
1345                    }),
1346                    upload_ids: vec![ID_ATTACHMENT],
1347                    suppress_previews: true,
1348                    poll: Some(crate::api::extras::PollInput {
1349                        question: "Lunch?".into(),
1350                        options: vec!["Tacos".into(), "Pizza".into()],
1351                        max_choices: None,
1352                        anonymous: false,
1353                        results_visibility: None,
1354                        duration_s: Some(3_600),
1355                    }),
1356                    clear_draft: true,
1357                },
1358            ),
1359            (
1360                "min",
1361                CreateMessageRequest {
1362                    body: "Deploying 0.41.0 now.".into(),
1363                    nonce: None,
1364                    thread_root_id: None,
1365                    also_send_to_channel: false,
1366                    reference: None,
1367                    upload_ids: Vec::new(),
1368                    suppress_previews: false,
1369                    poll: None,
1370                    clear_draft: false,
1371                },
1372            ),
1373        ]
1374    }
1375}
1376
1377impl Example for EditMessageRequest {
1378    fn examples() -> Vec<(&'static str, Self)> {
1379        vec![(
1380            "full",
1381            EditMessageRequest {
1382                body: "Deploying 0.41.1 now.".into(),
1383            },
1384        )]
1385    }
1386}
1387
1388impl Example for SetOnBehalfApprovalRequest {
1389    fn examples() -> Vec<(&'static str, Self)> {
1390        vec![(
1391            "full",
1392            SetOnBehalfApprovalRequest {
1393                state: OnBehalfApprovalState::Approved,
1394            },
1395        )]
1396    }
1397}
1398
1399impl Example for ForwardMessageRequest {
1400    fn examples() -> Vec<(&'static str, Self)> {
1401        vec![
1402            (
1403                "full",
1404                ForwardMessageRequest {
1405                    channel_id: ID_OTHER_CHANNEL,
1406                    thread_root_id: Some(ID_REPLY),
1407                    body: Some("FYI".into()),
1408                    nonce: Some(Nonce::new("fw-1")),
1409                    attachments: false,
1410                    suppress_previews: true,
1411                },
1412            ),
1413            (
1414                "min",
1415                ForwardMessageRequest {
1416                    channel_id: ID_OTHER_CHANNEL,
1417                    thread_root_id: None,
1418                    body: None,
1419                    nonce: None,
1420                    attachments: true,
1421                    suppress_previews: false,
1422                },
1423            ),
1424        ]
1425    }
1426}
1427
1428impl Example for ReactionRequest {
1429    fn examples() -> Vec<(&'static str, Self)> {
1430        vec![
1431            (
1432                "full",
1433                ReactionRequest {
1434                    emoji: EmojiInput::Unicode {
1435                        value: "🚀".into()
1436                    },
1437                },
1438            ),
1439            (
1440                "custom",
1441                ReactionRequest {
1442                    emoji: EmojiInput::Custom {
1443                        id: ID_EMOJI,
1444                        name: "party".into(),
1445                    },
1446                },
1447            ),
1448        ]
1449    }
1450}
1451
1452// ---------------------------------------------------------------- error
1453
1454impl Example for ErrorBody {
1455    fn examples() -> Vec<(&'static str, Self)> {
1456        vec![
1457            (
1458                "full",
1459                ErrorBody::new(ApiError::new(
1460                    Code::MissingPermission,
1461                    "SEND_MESSAGES in #deploys",
1462                )),
1463            ),
1464            (
1465                "rate_limited",
1466                ErrorBody::new(ApiError::new(Code::RateLimited, "slow down").with_details(
1467                    RetryAfterDetails {
1468                        retry_after_ms: 1_500,
1469                        reason: None,
1470                    },
1471                )),
1472            ),
1473            (
1474                "validation_failed",
1475                ErrorBody::new(ApiError {
1476                    code: Code::ValidationFailed,
1477                    hint: "unknown field `zz`".into(),
1478                    details: obj(json!({"field": "zz"})),
1479                }),
1480            ),
1481            (
1482                "resync_required",
1483                ErrorBody::new(
1484                    ApiError::new(Code::ResyncRequired, "cursor is behind the floor")
1485                        .with_details(ResyncRequiredDetails::new(900)),
1486                ),
1487            ),
1488        ]
1489    }
1490}
1491
1492impl Example for ValidationDetails {
1493    fn examples() -> Vec<(&'static str, Self)> {
1494        vec![(
1495            "full",
1496            ValidationDetails {
1497                field: "reference.kind".into(),
1498            },
1499        )]
1500    }
1501}
1502
1503impl Example for RetryAfterDetails {
1504    fn examples() -> Vec<(&'static str, Self)> {
1505        vec![(
1506            "full",
1507            RetryAfterDetails {
1508                retry_after_ms: 1_500,
1509                reason: Some(RATE_REASON_SLOW_MODE.into()),
1510            },
1511        )]
1512    }
1513}
1514
1515impl Example for ResyncRequiredDetails {
1516    fn examples() -> Vec<(&'static str, Self)> {
1517        vec![
1518            ("min", ResyncRequiredDetails::new(900)),
1519            (
1520                "full",
1521                ResyncRequiredDetails {
1522                    floor: 900,
1523                    head: Some(950),
1524                    reason: Some(ResyncReason::BehindFloor),
1525                    sync_epoch: Some("7713305120993321451".into()),
1526                },
1527            ),
1528        ]
1529    }
1530}
1531
1532impl Example for ReasonDetails {
1533    fn examples() -> Vec<(&'static str, Self)> {
1534        vec![
1535            (
1536                "full",
1537                ReasonDetails::with_field("username_taken", "username"),
1538            ),
1539            ("min", ReasonDetails::new("is_owner")),
1540        ]
1541    }
1542}
1543
1544impl Example for PermissionDeniedDetails {
1545    fn examples() -> Vec<(&'static str, Self)> {
1546        vec![
1547            (
1548                "full",
1549                PermissionDeniedDetails {
1550                    reason: PermissionReason::UnheldBits,
1551                    missing: Some(Perms::MANAGE_MESSAGES | Perms::TIMEOUT_MEMBERS),
1552                },
1553            ),
1554            (
1555                "min",
1556                PermissionDeniedDetails {
1557                    reason: PermissionReason::Hierarchy,
1558                    missing: None,
1559                },
1560            ),
1561        ]
1562    }
1563}
1564
1565impl Example for PolicyDeniedDetails {
1566    fn examples() -> Vec<(&'static str, Self)> {
1567        vec![(
1568            "full",
1569            PolicyDeniedDetails {
1570                policy: PolicyKey::GuestsInvite,
1571            },
1572        )]
1573    }
1574}
1575
1576impl Example for InvalidStateDetails {
1577    fn examples() -> Vec<(&'static str, Self)> {
1578        vec![(
1579            "full",
1580            InvalidStateDetails {
1581                reason: InvalidStateReason::ChannelArchived,
1582            },
1583        )]
1584    }
1585}
1586
1587// ---------------------------------------------------------------- http
1588
1589impl Example for PageQuery {
1590    fn examples() -> Vec<(&'static str, Self)> {
1591        vec![
1592            (
1593                "full",
1594                // Every field set is invalid (one cursor at most); the fixture shows the shape.
1595                PageQuery {
1596                    before: Some(ID_REPLY),
1597                    after: Some(ID_MESSAGE),
1598                    around: Some(ID_MESSAGE),
1599                    limit: Some(100),
1600                },
1601            ),
1602            ("min", PageQuery::default()),
1603            (
1604                "before",
1605                PageQuery {
1606                    before: Some(ID_REPLY),
1607                    limit: Some(50),
1608                    ..PageQuery::default()
1609                },
1610            ),
1611        ]
1612    }
1613}
1614
1615impl Example for ChangesQuery {
1616    fn examples() -> Vec<(&'static str, Self)> {
1617        vec![
1618            (
1619                "full",
1620                ChangesQuery {
1621                    since: 1_020,
1622                    limit: Some(500),
1623                },
1624            ),
1625            (
1626                "min",
1627                ChangesQuery {
1628                    since: 0,
1629                    limit: None,
1630                },
1631            ),
1632        ]
1633    }
1634}
1635
1636impl Example for EmptyRequest {
1637    fn examples() -> Vec<(&'static str, Self)> {
1638        vec![("full", EmptyRequest {})]
1639    }
1640}
1641
1642impl Example for OkResponse {
1643    fn examples() -> Vec<(&'static str, Self)> {
1644        vec![("full", OkResponse::default())]
1645    }
1646}
1647
1648// ---------------------------------------------------------------- gateway
1649
1650impl Example for Frame {
1651    fn examples() -> Vec<(&'static str, Self)> {
1652        vec![
1653            (
1654                "full",
1655                ServerOp::Dispatch {
1656                    s: 42,
1657                    event: Event::MessageDeleted(MessageDeleted {
1658                        id: ID_REPLY,
1659                        channel_id: ID_CHANNEL,
1660                        thread_root_id: Some(ID_MESSAGE),
1661                        seq: 1_030,
1662                        tombstone: false,
1663                        whole_thread: false,
1664                        channel_last_message_id: None,
1665                    }),
1666                }
1667                .encode(),
1668            ),
1669            ("min", ClientOp::Heartbeat(None).encode()),
1670            ("hello", ServerOp::Hello(Hello::default()).encode()),
1671            (
1672                "dispatch_message_created",
1673                ServerOp::Dispatch {
1674                    s: 2,
1675                    event: Event::MessageCreated(Box::new(message_min())),
1676                }
1677                .encode(),
1678            ),
1679            ("heartbeat", ClientOp::Heartbeat(Some(41)).encode()),
1680            ("heartbeat_ack", ServerOp::HeartbeatAck.encode()),
1681            ("identify", ClientOp::Identify(identify_ticket()).encode()),
1682        ]
1683    }
1684}
1685
1686impl Example for GatewayQuery {
1687    fn examples() -> Vec<(&'static str, Self)> {
1688        vec![
1689            (
1690                "full",
1691                GatewayQuery {
1692                    v: 1,
1693                    encoding: Encoding::Json,
1694                    compress: Some(Compression::ZstdStream),
1695                },
1696            ),
1697            (
1698                "min",
1699                GatewayQuery {
1700                    v: 1,
1701                    encoding: Encoding::Json,
1702                    compress: None,
1703                },
1704            ),
1705        ]
1706    }
1707}
1708
1709fn client_info() -> ClientInfo {
1710    ClientInfo {
1711        name: "sew-web".into(),
1712        version: "0.1.0".into(),
1713    }
1714}
1715
1716fn identify_ticket() -> IdentifyRequest {
1717    IdentifyRequest {
1718        auth: GatewayAuth::Ticket(ticket()),
1719        client: client_info(),
1720        capabilities: 0,
1721    }
1722}
1723
1724impl Example for IdentifyRequest {
1725    fn examples() -> Vec<(&'static str, Self)> {
1726        vec![
1727            ("full", identify_ticket()),
1728            (
1729                "full_token",
1730                IdentifyRequest {
1731                    auth: GatewayAuth::Token(session_token()),
1732                    client: client_info(),
1733                    capabilities: 0,
1734                },
1735            ),
1736        ]
1737    }
1738}
1739
1740impl Example for ResumeRequest {
1741    fn examples() -> Vec<(&'static str, Self)> {
1742        vec![
1743            (
1744                "full",
1745                ResumeRequest {
1746                    auth: GatewayAuth::Ticket(ticket()),
1747                    session_id: "gw_5f2b9c0e".into(),
1748                    seq: 41,
1749                },
1750            ),
1751            (
1752                "full_token",
1753                ResumeRequest {
1754                    auth: GatewayAuth::Token(session_token()),
1755                    session_id: "gw_5f2b9c0e".into(),
1756                    seq: 41,
1757                },
1758            ),
1759        ]
1760    }
1761}
1762
1763impl Example for PresenceSetRequest {
1764    fn examples() -> Vec<(&'static str, Self)> {
1765        vec![(
1766            "full",
1767            PresenceSetRequest {
1768                status: PresenceSetStatus::Dnd,
1769            },
1770        )]
1771    }
1772}
1773
1774impl Example for SubscribeRequest {
1775    fn examples() -> Vec<(&'static str, Self)> {
1776        vec![
1777            (
1778                "full",
1779                SubscribeRequest {
1780                    space_id: SubscribeScope::Space(ID_SPACE),
1781                    typing: vec![ID_CHANNEL],
1782                    presence: vec![ID_BOB, ID_CAROL],
1783                    member_list: Some(MemberListSub {
1784                        channel_id: ID_CHANNEL,
1785                        ranges: vec![[0, 99], [100, 199]],
1786                    }),
1787                },
1788            ),
1789            (
1790                "min",
1791                SubscribeRequest {
1792                    space_id: SubscribeScope::Dms,
1793                    typing: vec![],
1794                    presence: vec![],
1795                    member_list: None,
1796                },
1797            ),
1798        ]
1799    }
1800}
1801
1802impl Example for TypingRequest {
1803    fn examples() -> Vec<(&'static str, Self)> {
1804        vec![
1805            (
1806                "full",
1807                TypingRequest {
1808                    channel_id: ID_CHANNEL,
1809                    thread_id: Some(ID_MESSAGE),
1810                },
1811            ),
1812            (
1813                "min",
1814                TypingRequest {
1815                    channel_id: ID_CHANNEL,
1816                    thread_id: None,
1817                },
1818            ),
1819        ]
1820    }
1821}
1822
1823impl Example for ReauthRequest {
1824    fn examples() -> Vec<(&'static str, Self)> {
1825        vec![(
1826            "full",
1827            ReauthRequest {
1828                token: session_token(),
1829            },
1830        )]
1831    }
1832}
1833
1834impl Example for ActivityRequest {
1835    fn examples() -> Vec<(&'static str, Self)> {
1836        vec![("full", ActivityRequest { idle: true })]
1837    }
1838}
1839
1840impl Example for Hello {
1841    fn examples() -> Vec<(&'static str, Self)> {
1842        vec![("full", Hello::default())]
1843    }
1844}
1845
1846impl Example for Reconnect {
1847    fn examples() -> Vec<(&'static str, Self)> {
1848        vec![("full", Reconnect { after_ms: 7_312 })]
1849    }
1850}
1851
1852impl Example for InvalidSession {
1853    fn examples() -> Vec<(&'static str, Self)> {
1854        vec![("full", InvalidSession { resumable: false })]
1855    }
1856}
1857
1858impl Example for CallReady {
1859    fn examples() -> Vec<(&'static str, Self)> {
1860        vec![(
1861            "full",
1862            CallReady {
1863                v: crate::PROTOCOL_VERSION,
1864                session_id: "gw_5f2b9c0e".into(),
1865                user: CallReadyUser { id: ID_ME },
1866                install_id: ID_INSTALL,
1867                call_keys: Some(call_keys::ready_call_keys_full()),
1868                recording: Some(recording::recording_full()),
1869                recording_controls: Some(recording::controls_in_recording()),
1870            },
1871        )]
1872    }
1873}
1874
1875impl Example for CallReadyUser {
1876    fn examples() -> Vec<(&'static str, Self)> {
1877        vec![("full", CallReadyUser { id: ID_ME })]
1878    }
1879}
1880
1881impl Example for RateLimitedCloseReason {
1882    fn examples() -> Vec<(&'static str, Self)> {
1883        vec![(
1884            "full",
1885            RateLimitedCloseReason {
1886                retry_after_ms: 5_000,
1887            },
1888        )]
1889    }
1890}
1891
1892fn ready_full() -> Ready {
1893    Ready {
1894        session_id: "gw_5f2b9c0e".into(),
1895        resume_url: "wss://chat.example.com/api/v1/gateway".into(),
1896        protocol: crate::PROTOCOL_VERSION,
1897        member: member_min(),
1898        install: ReadyInstall {
1899            id: ID_INSTALL,
1900            name: "Acme".into(),
1901            policy_digest: Policies::default().digest(),
1902            sync_epoch: "7713305120993321451".into(),
1903            profile_fields_version: Some("3".into()),
1904            voice_enabled: true,
1905            video_enabled: true,
1906            media: Some(calls::media_policy_full()),
1907            recording_controls: true,
1908            read_receipts: Some(read_receipts::settings_full()),
1909        },
1910        spaces: vec![ReadySpace {
1911            id: ID_SPACE,
1912            slug: slug("acme-eng"),
1913            name: "Acme Engineering".into(),
1914            icon_url: Some("/api/v1/space-icons/48831765147549697/48831765147549716/512?exp=1791158400&sig=c2ln".into()),
1915            icon_thumb_url: Some("/api/v1/space-icons/48831765147549697/48831765147549716/64?exp=1791158400&sig=c2ln".into()),
1916            my_role_ids: vec![ID_ROLE],
1917            member_count: 42,
1918            versions: ReadyVersions {
1919                emoji: "e-3".into(),
1920                roles: "r7".into(),
1921                groups: "g-1".into(),
1922            },
1923            my_space_perms: perms::DEFAULT_EVERYONE,
1924            hidden: true,
1925            app_id: Some("atrium".into()),
1926            app_display_name: Some("Atrium".into()),
1927            participant_app_ids: vec!["jobs".into()],
1928            private: true,
1929            orphaned_from: Some("atrium".into()),
1930            governance: SpaceGovernance::App,
1931        }],
1932        categories: vec![ReadyCategory {
1933            id: ID_CATEGORY,
1934            space_id: ID_SPACE,
1935            name: "Engineering".into(),
1936            position: 1,
1937        }],
1938        channels: vec![
1939            ReadyChannel {
1940                id: ID_CHANNEL,
1941                space_id: Some(ID_SPACE),
1942                category_id: Some(ID_CATEGORY),
1943                kind: ChannelType::Text,
1944                visibility: Visibility::Public,
1945                slug: Some(slug("deploys")),
1946                name: Some("deploys".into()),
1947                position: 4,
1948                head_seq: 1_024,
1949                last_message_id: Some(ID_MESSAGE),
1950                my_perms: perms::DEFAULT_EVERYONE,
1951                dm_member_ids: vec![],
1952                slow_mode_s: Some(30),
1953                retention_days: Some(90),
1954                file_retention_days: Some(30),
1955                has_guests: true,
1956                assistant_reader_ids: vec![],
1957                recording_auto: false,
1958                recording_audio_days: None,
1959                recording_require_consent: None,
1960                recording_required: None,
1961                recording_rule: crate::recording::RecordingRule::None,
1962                members_can_leave: true,
1963                dm_seen: vec![],
1964                voice_invites: vec![],
1965            },
1966            ReadyChannel {
1967                id: ID_DM,
1968                space_id: None,
1969                category_id: None,
1970                kind: ChannelType::Dm,
1971                visibility: Visibility::Private,
1972                slug: None,
1973                name: None,
1974                position: 0,
1975                head_seq: 3,
1976                last_message_id: None,
1977                my_perms: Perms(0b1110_1111),
1978                dm_member_ids: vec![ID_ME, ID_BOB],
1979                slow_mode_s: None,
1980                retention_days: None,
1981                file_retention_days: None,
1982                has_guests: false,
1983                assistant_reader_ids: vec![ID_CAROL],
1984                recording_auto: false,
1985                recording_audio_days: None,
1986                recording_require_consent: None,
1987                recording_required: None,
1988                recording_rule: crate::recording::RecordingRule::None,
1989                members_can_leave: false,
1990                dm_seen: vec![read_receipts::dm_seen_full()],
1991                voice_invites: vec![],
1992            },
1993            // An auto-record voice channel.
1994            ReadyChannel {
1995                id: ID_OTHER_CHANNEL,
1996                space_id: Some(ID_SPACE),
1997                category_id: Some(ID_CATEGORY),
1998                kind: ChannelType::Voice,
1999                visibility: Visibility::Public,
2000                slug: Some(slug("standup")),
2001                name: Some("standup".into()),
2002                position: 5,
2003                head_seq: 7,
2004                last_message_id: None,
2005                my_perms: perms::DEFAULT_EVERYONE,
2006                dm_member_ids: vec![],
2007                slow_mode_s: None,
2008                retention_days: None,
2009                file_retention_days: None,
2010                has_guests: false,
2011                assistant_reader_ids: vec![],
2012                recording_auto: true,
2013                recording_audio_days: Some(30),
2014                recording_require_consent: Some(true),
2015                recording_required: Some(true),
2016                recording_rule: crate::recording::RecordingRule::Auto,
2017                members_can_leave: false,
2018                dm_seen: vec![],
2019                voice_invites: vec![voice_notify::invite_in(ID_OTHER_CHANNEL)],
2020            },
2021        ],
2022        read_states: vec![read_state::ready_read_state()],
2023        member_seq: 78,
2024        threads_inbox: read_state::inbox_full(),
2025        presence_settings: Some(people::presence_settings_full()),
2026        dm_members: vec![member_full()],
2027        notify: Some(notify::ready_notify_full()),
2028        call_keys: Some(call_keys::ready_call_keys_full()),
2029        voice_states: vec![voice::voice_state_full()],
2030        voice_states_partial: true,
2031        voice_channels: vec![voice::ready_voice_channel_full()],
2032        calls: vec![calls::call_full()],
2033        recordings: vec![recording::recording_full()],
2034    }
2035}
2036
2037impl Example for Ready {
2038    fn examples() -> Vec<(&'static str, Self)> {
2039        vec![("full", ready_full())]
2040    }
2041}
2042
2043impl Example for Resumed {
2044    fn examples() -> Vec<(&'static str, Self)> {
2045        vec![("full", Resumed {})]
2046    }
2047}
2048
2049impl Example for MessageDeleted {
2050    fn examples() -> Vec<(&'static str, Self)> {
2051        vec![
2052            (
2053                "full",
2054                MessageDeleted {
2055                    id: ID_REPLY,
2056                    channel_id: ID_CHANNEL,
2057                    thread_root_id: Some(ID_MESSAGE),
2058                    seq: 1_031,
2059                    tombstone: true,
2060                    whole_thread: false,
2061                    channel_last_message_id: Some(ID_MESSAGE),
2062                },
2063            ),
2064            (
2065                "min",
2066                MessageDeleted {
2067                    id: ID_MESSAGE,
2068                    channel_id: ID_CHANNEL,
2069                    thread_root_id: None,
2070                    seq: 1_032,
2071                    tombstone: false,
2072                    whole_thread: false,
2073                    channel_last_message_id: None,
2074                },
2075            ),
2076        ]
2077    }
2078}
2079
2080impl Example for ReactionEvent {
2081    fn examples() -> Vec<(&'static str, Self)> {
2082        vec![(
2083            "full",
2084            ReactionEvent {
2085                message_id: ID_MESSAGE,
2086                channel_id: ID_CHANNEL,
2087                member_id: ID_BOB,
2088                emoji: Emoji::Unicode {
2089                    value: "👍".into()
2090                },
2091                count: 2,
2092                seq: 1_033,
2093            },
2094        )]
2095    }
2096}
2097
2098impl Example for ChannelMemberEvent {
2099    fn examples() -> Vec<(&'static str, Self)> {
2100        vec![
2101            (
2102                "full",
2103                ChannelMemberEvent {
2104                    channel_id: ID_CHANNEL,
2105                    member_id: ID_BOB,
2106                    seq: Some(1_025),
2107                    channel: Some(Box::new(channel_full())),
2108                    person: Some(crate::api::meetings::MeetingPerson {
2109                        member_id: ID_BOB,
2110                        display_name: "Bob Builder".into(),
2111                        kind: crate::api::meetings::MeetingLobbyKind::Member,
2112                    }),
2113                },
2114            ),
2115            (
2116                "min",
2117                ChannelMemberEvent {
2118                    channel_id: ID_CHANNEL,
2119                    member_id: ID_BOB,
2120                    seq: None,
2121                    channel: None,
2122                    person: None,
2123                },
2124            ),
2125        ]
2126    }
2127}
2128
2129impl Example for TypingStarted {
2130    fn examples() -> Vec<(&'static str, Self)> {
2131        vec![
2132            (
2133                "full",
2134                TypingStarted {
2135                    channel_id: ID_CHANNEL,
2136                    thread_id: Some(ID_MESSAGE),
2137                    member_id: ID_BOB,
2138                },
2139            ),
2140            (
2141                "min",
2142                TypingStarted {
2143                    channel_id: ID_CHANNEL,
2144                    thread_id: None,
2145                    member_id: ID_BOB,
2146                },
2147            ),
2148        ]
2149    }
2150}
2151
2152impl Example for PresenceUpdated {
2153    fn examples() -> Vec<(&'static str, Self)> {
2154        vec![(
2155            "full",
2156            PresenceUpdated {
2157                member_id: ID_BOB,
2158                status: PresenceStatus::Idle,
2159            },
2160        )]
2161    }
2162}
2163
2164impl Example for PermsChanged {
2165    fn examples() -> Vec<(&'static str, Self)> {
2166        vec![
2167            (
2168                "full",
2169                PermsChanged {
2170                    space_id: Some(ID_SPACE),
2171                    channels: vec![ChannelPerms {
2172                        channel_id: ID_CHANNEL,
2173                        my_perms: perms::DEFAULT_EVERYONE,
2174                    }],
2175                    my_space_perms: Some(perms::DEFAULT_EVERYONE),
2176                    full: true,
2177                },
2178            ),
2179            (
2180                "min",
2181                PermsChanged {
2182                    space_id: None,
2183                    channels: vec![],
2184                    my_space_perms: None,
2185                    full: false,
2186                },
2187            ),
2188        ]
2189    }
2190}
2191
2192// ---------------------------------------------------------------- mgmt
2193
2194impl Example for Health {
2195    fn examples() -> Vec<(&'static str, Self)> {
2196        vec![("full", Health { ok: true })]
2197    }
2198}
2199
2200impl Example for Status {
2201    fn examples() -> Vec<(&'static str, Self)> {
2202        let min = Status {
2203            version: "0.1.0".into(),
2204            schema_version: 90_001,
2205            install_id: ID_INSTALL,
2206            provider: ProviderKind::K2,
2207            db: StatusDb {
2208                ok: true,
2209                lag_ms: None,
2210                ping_ms: None,
2211            },
2212            jobs: StatusJobs {
2213                queued: 3,
2214                dead: 0,
2215                running: 0,
2216                oldest_due_age_ms: None,
2217            },
2218            search: StatusSearch::default(),
2219            keys: StatusKeys {
2220                provider_ok: true,
2221                current_month_ready: true,
2222                mirror_ok: false,
2223                mirror_age_ms: None,
2224                provider: None,
2225                kek_id: None,
2226                retiring_kek_ids: Vec::new(),
2227                rewrap_pending: 0,
2228                next_month_prepared: false,
2229                lazy_creates_this_month: 0,
2230                shred_pending: 0,
2231                resurrected_keys: 0,
2232                mirror: None,
2233            },
2234            sessions: 12,
2235            sockets: 9,
2236            started_at: None,
2237            uptime_ms: 0,
2238            alarms: Vec::new(),
2239            identity: None,
2240            client_listen: None,
2241            backup: None,
2242            drill: None,
2243            files: None,
2244            retention: None,
2245            mail: None,
2246            digest: None,
2247            exports: None,
2248            erasures: None,
2249            voice: None,
2250            recording: None,
2251            features: Vec::new(),
2252            gateway: None,
2253        };
2254        let full = Status {
2255            db: StatusDb {
2256                ok: true,
2257                lag_ms: Some(0),
2258                ping_ms: Some(1),
2259            },
2260            jobs: StatusJobs {
2261                queued: 3,
2262                dead: 1,
2263                running: 1,
2264                oldest_due_age_ms: Some(120),
2265            },
2266            search: StatusSearch {
2267                lag_ms: Some(1_200),
2268                state: Some(SearchState::Ready),
2269                docs: Some(StatusSearchDocs {
2270                    messages: 1_203_311,
2271                    files: 88_410,
2272                }),
2273                index_bytes: Some(81_234_567),
2274                generation: Some(7),
2275                last_commit_at: Some(t(1_100)),
2276                rebuild: Some(StatusSearchRebuild {
2277                    reason: "admin".into(),
2278                    generation: 8,
2279                    progress_pct: 41,
2280                    docs: 493_000,
2281                    started_at: t(0),
2282                }),
2283            },
2284            keys: StatusKeys {
2285                provider_ok: true,
2286                current_month_ready: true,
2287                mirror_ok: true,
2288                mirror_age_ms: Some(60_000),
2289                provider: Some("systemd-credential".into()),
2290                kek_id: Some("1f2e3d4c5b6a7988".into()),
2291                retiring_kek_ids: vec!["0a1b2c3d4e5f6071".into()],
2292                rewrap_pending: 12,
2293                next_month_prepared: true,
2294                lazy_creates_this_month: 0,
2295                shred_pending: 0,
2296                resurrected_keys: 0,
2297                mirror: Some(StatusKeysMirror {
2298                    kind: "dir".into(),
2299                    stale: false,
2300                    pending: 1,
2301                    oldest_pending_age_s: Some(4),
2302                    last_ok_at: Some(t(60_000)),
2303                    unknown_keys: 0,
2304                }),
2305            },
2306            started_at: Some(t(0)),
2307            uptime_ms: 3_600_000,
2308            alarms: vec![StatusAlarm::BackupStale, StatusAlarm::JobsDead],
2309            identity: Some(StatusIdentity {
2310                provider: ProviderKind::K2,
2311                jwks_url: Some("http://127.0.0.1:7300/v1/chat/jwks".into()),
2312                jwks_ok: Some(true),
2313                mode: Some(ProviderKind::K2),
2314                switched_at: Some(t(1_800_000)),
2315                unlinked_local_members: Some(2),
2316                restart_required: true,
2317            }),
2318            client_listen: Some("http://127.0.0.1:8470".into()),
2319            backup: Some(StatusBackup {
2320                last_ok_at: Some(t(0)),
2321                last_id: Some("20260927T031512Z".into()),
2322                age_ms: Some(129_600_001),
2323                last_error: Some("disk_full".into()),
2324                last_kind: Some("scheduled".into()),
2325                last_error_at: Some(t(3_600_000)),
2326            }),
2327            drill: Some(StatusDrill {
2328                last_ok_at: Some(t(0)),
2329                last_ok: Some(true),
2330                last_error: Some("checksum_mismatch".into()),
2331                age_ms: Some(86_400_000),
2332            }),
2333            files: Some(StatusFiles {
2334                ffmpeg_available: true,
2335            }),
2336            retention: Some(crate::api::compliance::StatusRetention {
2337                last_run_at: Some(t(7_200_000)),
2338                last_run_state: Some(crate::api::compliance::RunState::Done),
2339                last_ok_at: Some(t(7_200_000)),
2340                overdue: false,
2341                pending_policies: 1,
2342                active_holds: 2,
2343                search_pending: 0,
2344                shred_candidates: 14,
2345            }),
2346            mail: Some(notify::status_mail_full()),
2347            digest: Some(StatusDigest {
2348                enabled: true,
2349                pending_jobs: 3,
2350            }),
2351            exports: Some(crate::api::exports::StatusExports {
2352                running: Some(ID_JOB),
2353                queued: 2,
2354                on_disk_bytes: 104_857_600,
2355                last_done_at: Some(t(3_600_000)),
2356                last_failed_at: Some(t(1_800_000)),
2357            }),
2358            erasures: Some(StatusErasures {
2359                running: 1,
2360                waiting: 2,
2361                oldest_running_age_ms: Some(4_000),
2362            }),
2363            features: features(),
2364            gateway: Some(status_gateway_full()),
2365            ..min.clone()
2366        };
2367        let voice = Status {
2368            alarms: vec![StatusAlarm::E2eeRosterMismatch, StatusAlarm::VoiceMediaDown],
2369            voice: Some(voice::voice_status_full()),
2370            ..min.clone()
2371        };
2372        let recording = Status {
2373            alarms: vec![StatusAlarm::RecorderDown, StatusAlarm::TranscribeBacklog],
2374            recording: Some(recording::status_recording_full()),
2375            ..min.clone()
2376        };
2377        vec![
2378            ("full", full),
2379            ("full_voice", voice),
2380            ("full_recording", recording),
2381            ("min", min),
2382        ]
2383    }
2384}
2385
2386/// `status.gateway` with every key (0.7.1).
2387fn status_gateway_full() -> StatusGateway {
2388    let mut closes = std::collections::BTreeMap::new();
2389    for code in [
2390        "4000", "4001", "4002", "4003", "4004", "4005", "4007", "4008", "4009", "4010", "4011",
2391        "4012", "4013", "4014", "stall",
2392    ] {
2393        closes.insert(code.to_owned(), 0);
2394    }
2395    closes.insert("4003".to_owned(), 2);
2396    closes.insert("4008".to_owned(), 17);
2397    StatusGateway {
2398        sockets_live: 40,
2399        sockets_pending: 1,
2400        identify: StatusGatewayIdentify {
2401            ok: 310,
2402            rate_limited: 17,
2403            auth_failed: 1,
2404            timeout: 2,
2405            error: 0,
2406        },
2407        resume: StatusGatewayResume {
2408            resumed: 95,
2409            invalid: 3,
2410            bad_seq: 0,
2411            rate_limited: 0,
2412            auth_failed: 0,
2413            timeout: 0,
2414        },
2415        reauth: StatusGatewayReauth {
2416            ok: 12,
2417            auth_failed: 0,
2418            timeout: 0,
2419        },
2420        closes,
2421    }
2422}
2423
2424fn provision_agent() -> ProvisionRequest {
2425    ProvisionRequest {
2426        external_id: ext(WORKSPACE),
2427        kind: MemberKind::Agent,
2428        agent_kind: Some(AgentKind::Assistant),
2429        assistant_of: Some(ext(PRINCIPAL)),
2430        guest: false,
2431        profile: ProfileInput {
2432            display_name: "Morgan's assistant".into(),
2433            username: handle("morgan-assistant"),
2434            email: Some("assistant@example.com".into()),
2435            title: Some("Assistant".into()),
2436            pronouns: Some("it/its".into()),
2437            custom_fields: vec![crate::api::people::MgmtCustomFieldInput {
2438                key: "cost_center".into(),
2439                value: Some("42".into()),
2440            }],
2441        },
2442    }
2443}
2444
2445impl Example for ProvisionRequest {
2446    fn examples() -> Vec<(&'static str, Self)> {
2447        let min = ProvisionRequest {
2448            external_id: ext(PRINCIPAL),
2449            kind: MemberKind::Person,
2450            agent_kind: None,
2451            assistant_of: None,
2452            guest: false,
2453            profile: ProfileInput {
2454                display_name: "Morgan".into(),
2455                username: handle("morgan"),
2456                email: None,
2457                title: None,
2458                pronouns: None,
2459                custom_fields: vec![],
2460            },
2461        };
2462        // A K2 Connect user of the server, a person and a member.
2463        let connect = ProvisionRequest {
2464            external_id: ext(CONNECT_USER),
2465            kind: MemberKind::Person,
2466            agent_kind: None,
2467            assistant_of: None,
2468            guest: false,
2469            profile: ProfileInput {
2470                display_name: "Dana from Connect".into(),
2471                username: handle("dana"),
2472                email: None,
2473                title: None,
2474                pronouns: None,
2475                custom_fields: vec![],
2476            },
2477        };
2478        vec![
2479            ("full", provision_agent()),
2480            ("min", min),
2481            ("connect", connect),
2482        ]
2483    }
2484}
2485
2486impl Example for ProvisionResponse {
2487    fn examples() -> Vec<(&'static str, Self)> {
2488        vec![(
2489            "full",
2490            ProvisionResponse {
2491                member_id: ID_CAROL,
2492                created: true,
2493                reactivated: false,
2494                changed: false,
2495            },
2496        )]
2497    }
2498}
2499
2500impl Example for UpdatePrincipalRequest {
2501    fn examples() -> Vec<(&'static str, Self)> {
2502        vec![
2503            (
2504                "full",
2505                UpdatePrincipalRequest {
2506                    external_id: ext(PRINCIPAL),
2507                    profile: ProfilePatch {
2508                        display_name: Some("Morgan L.".into()),
2509                        username: Some(handle("morgan")),
2510                        email: Patch::Set("morgan@example.com".into()),
2511                        title: Patch::Clear,
2512                        pronouns: Patch::Set("he/him".into()),
2513                        custom_fields: vec![crate::api::people::MgmtCustomFieldInput {
2514                            key: "cost_center".into(),
2515                            value: None,
2516                        }],
2517                    },
2518                },
2519            ),
2520            (
2521                "min",
2522                UpdatePrincipalRequest {
2523                    external_id: ext(PRINCIPAL),
2524                    profile: ProfilePatch::default(),
2525                },
2526            ),
2527        ]
2528    }
2529}
2530
2531impl Example for PrincipalRelinkRequest {
2532    fn examples() -> Vec<(&'static str, Self)> {
2533        vec![(
2534            "full",
2535            PrincipalRelinkRequest {
2536                from: ext("local:bob"),
2537                to: ext(PRINCIPAL),
2538            },
2539        )]
2540    }
2541}
2542
2543impl Example for PrincipalRelinkResponse {
2544    fn examples() -> Vec<(&'static str, Self)> {
2545        vec![(
2546            "full",
2547            PrincipalRelinkResponse {
2548                member_id: ID_BOB,
2549                from: ext("local:bob"),
2550                to: ext(PRINCIPAL),
2551                changed: true,
2552                sessions_revoked: 2,
2553            },
2554        )]
2555    }
2556}
2557
2558impl Example for IdentitySwitchRequest {
2559    fn examples() -> Vec<(&'static str, Self)> {
2560        vec![(
2561            "full",
2562            IdentitySwitchRequest {
2563                to: ProviderKind::K2,
2564                confirm: true,
2565            },
2566        )]
2567    }
2568}
2569
2570impl Example for IdentitySwitchResponse {
2571    fn examples() -> Vec<(&'static str, Self)> {
2572        vec![(
2573            "full",
2574            IdentitySwitchResponse {
2575                mode: ProviderKind::K2,
2576                switched_at: t(1_800_000),
2577                restart_required: true,
2578                unlinked_local_members: 3,
2579            },
2580        )]
2581    }
2582}
2583
2584impl Example for DeprovisionRequest {
2585    fn examples() -> Vec<(&'static str, Self)> {
2586        vec![(
2587            "full",
2588            DeprovisionRequest {
2589                external_id: ext(PRINCIPAL),
2590            },
2591        )]
2592    }
2593}
2594
2595impl Example for DeprovisionResponse {
2596    fn examples() -> Vec<(&'static str, Self)> {
2597        vec![(
2598            "full",
2599            DeprovisionResponse {
2600                member_id: ID_BOB,
2601                sessions_revoked: 2,
2602            },
2603        )]
2604    }
2605}
2606
2607impl Example for MgmtEraseRequest {
2608    fn examples() -> Vec<(&'static str, Self)> {
2609        vec![
2610            (
2611                "full",
2612                MgmtEraseRequest {
2613                    external_id: ext(PRINCIPAL),
2614                    mode: Some(EraseMode::DeleteContent),
2615                    dry_run: true,
2616                },
2617            ),
2618            (
2619                "min",
2620                MgmtEraseRequest {
2621                    external_id: ext(PRINCIPAL),
2622                    mode: None,
2623                    dry_run: false,
2624                },
2625            ),
2626        ]
2627    }
2628}
2629
2630fn erase_result() -> MgmtEraseResult {
2631    MgmtEraseResult {
2632        job_id: ID_JOB,
2633        member_id: ID_BOB,
2634        mode: EraseMode::DeleteContent,
2635        dry_run: false,
2636        state: EraseState::Waiting,
2637        requested_at: t(0),
2638        finished_at: None,
2639        erased: MgmtEraseCounts {
2640            profile: 1,
2641            sessions: 3,
2642            devices: 2,
2643            notify_settings: 1,
2644            drafts: 0,
2645            read_positions: 57,
2646            saved_items: 4,
2647            uploads_pending: 1,
2648            messages_deleted: 1204,
2649            messages_anonymised: 0,
2650            reactions: 88,
2651            poll_votes: 3,
2652            files: 31,
2653            recordings: 1,
2654            recording_segments: 40,
2655            forward_snapshots: 2,
2656            assistants: 1,
2657        },
2658        kept: vec![
2659            MgmtEraseKept {
2660                kind: EraseKeptKind::Messages,
2661                count: 200,
2662                reason: EraseKeptReason::LegalHold,
2663                until: None,
2664            },
2665            MgmtEraseKept {
2666                kind: EraseKeptKind::Files,
2667                count: 2,
2668                reason: EraseKeptReason::SharedWithOthers,
2669                until: None,
2670            },
2671            MgmtEraseKept {
2672                kind: EraseKeptKind::Backups,
2673                count: 9,
2674                reason: EraseKeptReason::BackupRetention,
2675                until: Some(t(90_000_000)),
2676            },
2677        ],
2678        pending_until: None,
2679    }
2680}
2681
2682impl Example for MgmtEraseResult {
2683    fn examples() -> Vec<(&'static str, Self)> {
2684        vec![
2685            ("full", erase_result()),
2686            (
2687                "full_completed",
2688                MgmtEraseResult {
2689                    mode: EraseMode::Anonymise,
2690                    state: EraseState::Completed,
2691                    finished_at: Some(t(2_000)),
2692                    erased: MgmtEraseCounts {
2693                        profile: 1,
2694                        sessions: 1,
2695                        ..MgmtEraseCounts::default()
2696                    },
2697                    kept: vec![MgmtEraseKept {
2698                        kind: EraseKeptKind::Backups,
2699                        count: 2,
2700                        reason: EraseKeptReason::BackupRetention,
2701                        until: Some(t(90_000_000)),
2702                    }],
2703                    pending_until: Some(t(90_000_000)),
2704                    ..erase_result()
2705                },
2706            ),
2707        ]
2708    }
2709}
2710
2711impl Example for MgmtEraseAccepted {
2712    fn examples() -> Vec<(&'static str, Self)> {
2713        vec![(
2714            "full",
2715            MgmtEraseAccepted {
2716                job_id: ID_JOB,
2717                member_id: ID_BOB,
2718                mode: EraseMode::DeleteContent,
2719                pending: true,
2720            },
2721        )]
2722    }
2723}
2724
2725impl Example for MgmtErasuresQuery {
2726    fn examples() -> Vec<(&'static str, Self)> {
2727        vec![
2728            (
2729                "full",
2730                MgmtErasuresQuery {
2731                    state: Some(EraseState::Waiting),
2732                    after: Some(ID_JOB),
2733                    limit: Some(100),
2734                },
2735            ),
2736            ("min", MgmtErasuresQuery::default()),
2737        ]
2738    }
2739}
2740
2741impl Example for MgmtErasurePage {
2742    fn examples() -> Vec<(&'static str, Self)> {
2743        vec![
2744            (
2745                "full",
2746                MgmtErasurePage {
2747                    items: vec![erase_result()],
2748                    next: Some(ID_JOB),
2749                },
2750            ),
2751            (
2752                "last",
2753                MgmtErasurePage {
2754                    items: vec![],
2755                    next: None,
2756                },
2757            ),
2758        ]
2759    }
2760}
2761
2762impl Example for RevokeSessionsRequest {
2763    fn examples() -> Vec<(&'static str, Self)> {
2764        vec![
2765            (
2766                "full",
2767                RevokeSessionsRequest {
2768                    external_id: Some(ext(PRINCIPAL)),
2769                    k2_sid: Some("skn_4f1c2a".into()),
2770                    app_id: None,
2771                },
2772            ),
2773            (
2774                "k2_sid",
2775                RevokeSessionsRequest {
2776                    external_id: None,
2777                    k2_sid: Some("own_0123456789abcdef0123456789abcdef".into()),
2778                    app_id: None,
2779                },
2780            ),
2781            (
2782                "full_app",
2783                RevokeSessionsRequest {
2784                    external_id: Some(ext(PRINCIPAL)),
2785                    k2_sid: None,
2786                    app_id: Some("jobs".into()),
2787                },
2788            ),
2789            (
2790                "app_id",
2791                RevokeSessionsRequest {
2792                    external_id: None,
2793                    k2_sid: None,
2794                    app_id: Some("jobs".into()),
2795                },
2796            ),
2797        ]
2798    }
2799}
2800
2801impl Example for RevokeSessionsResponse {
2802    fn examples() -> Vec<(&'static str, Self)> {
2803        vec![("full", RevokeSessionsResponse { revoked: 2 })]
2804    }
2805}
2806
2807impl Example for OwnerSetRequest {
2808    fn examples() -> Vec<(&'static str, Self)> {
2809        vec![
2810            (
2811                "full",
2812                OwnerSetRequest {
2813                    external_id: ext(PRINCIPAL),
2814                    approval: Some(OwnerApproval::OwnerPass { pass: PASS.into() }),
2815                    force: true,
2816                },
2817            ),
2818            (
2819                "min",
2820                OwnerSetRequest {
2821                    external_id: ExternalId::K2Owner,
2822                    approval: None,
2823                    force: false,
2824                },
2825            ),
2826            (
2827                "password",
2828                OwnerSetRequest {
2829                    external_id: ext("local:bob"),
2830                    approval: Some(OwnerApproval::OwnerPassword {
2831                        password: "correct horse battery staple".into(),
2832                    }),
2833                    force: false,
2834                },
2835            ),
2836        ]
2837    }
2838}
2839
2840impl Example for PinRequest {
2841    fn examples() -> Vec<(&'static str, Self)> {
2842        vec![(
2843            "full",
2844            PinRequest {
2845                agent: ext(WORKSPACE),
2846                person: ext(PRINCIPAL),
2847            },
2848        )]
2849    }
2850}
2851
2852impl Example for DeliveriesQuery {
2853    fn examples() -> Vec<(&'static str, Self)> {
2854        vec![
2855            (
2856                "full",
2857                DeliveriesQuery {
2858                    after: 77,
2859                    timeout_ms: Some(25_000),
2860                    limit: Some(100),
2861                },
2862            ),
2863            (
2864                "min",
2865                DeliveriesQuery {
2866                    after: 77,
2867                    timeout_ms: None,
2868                    limit: None,
2869                },
2870            ),
2871        ]
2872    }
2873}
2874
2875impl Example for DeliveriesPage {
2876    fn examples() -> Vec<(&'static str, Self)> {
2877        vec![(
2878            "full",
2879            DeliveriesPage {
2880                entries: vec![
2881                    Delivery {
2882                        seq: 78,
2883                        at: t(60_000),
2884                        reason: NotificationReason::Mention,
2885                        message: DeliveryMessage {
2886                            id: ID_REPLY,
2887                            channel_id: ID_CHANNEL,
2888                            space_id: Some(ID_SPACE),
2889                            thread_root_id: Some(ID_MESSAGE),
2890                            author_id: ID_BOB,
2891                            author_display_name: "Bob".into(),
2892                            author_username: Some(handle("bob")),
2893                            author_kind: MemberKind::Person,
2894                            addr: addr("acme-eng/#deploys/48831765147549701"),
2895                            reply_addr: Some(addr("acme-eng/#deploys/48831765147549701")),
2896                            place: Some(DeliveryPlace::SpaceChannel),
2897                            kind: DeliveryKind::Text,
2898                            call: None,
2899                            recording: Some(recording::recording_summary_full()),
2900                            body: "@morgan-assistant can you check the logs?".into(),
2901                            body_truncated: false,
2902                            attachment_count: 1,
2903                            on_behalf_of: None,
2904                            on_behalf_of_display_name: None,
2905                            created_at: t(60_000),
2906                        },
2907                    },
2908                    Delivery {
2909                        seq: 79,
2910                        at: t(120_000),
2911                        reason: NotificationReason::Dm,
2912                        message: DeliveryMessage {
2913                            id: ID_MESSAGE,
2914                            channel_id: ID_DM,
2915                            space_id: None,
2916                            thread_root_id: None,
2917                            author_id: ID_BOB,
2918                            author_display_name: "Bob".into(),
2919                            author_username: Some(handle("bob")),
2920                            author_kind: MemberKind::Agent,
2921                            addr: addr("dm/id:48831765147549711"),
2922                            reply_addr: None,
2923                            place: Some(DeliveryPlace::PersonDm),
2924                            kind: DeliveryKind::CallRecord,
2925                            call: Some(DeliveryCall {
2926                                missed: false,
2927                                duration_ms: Some(90_000),
2928                            }),
2929                            recording: None,
2930                            body: "ping".into(),
2931                            body_truncated: true,
2932                            attachment_count: 0,
2933                            on_behalf_of: Some(ID_CAROL),
2934                            on_behalf_of_display_name: Some("Carol".into()),
2935                            created_at: t(120_000),
2936                        },
2937                    },
2938                ],
2939                head: 81,
2940                next_after: 80,
2941                has_more: true,
2942                sync_epoch: Some("7713305120993321451".into()),
2943            },
2944        )]
2945    }
2946}
2947
2948impl Example for PersonNotificationsQuery {
2949    fn examples() -> Vec<(&'static str, Self)> {
2950        vec![
2951            (
2952                "full",
2953                PersonNotificationsQuery {
2954                    after: 77,
2955                    limit: Some(100),
2956                    wait: Some(30),
2957                },
2958            ),
2959            (
2960                "min",
2961                PersonNotificationsQuery {
2962                    after: 77,
2963                    limit: None,
2964                    wait: None,
2965                },
2966            ),
2967        ]
2968    }
2969}
2970
2971impl Example for PersonNotificationsPage {
2972    fn examples() -> Vec<(&'static str, Self)> {
2973        let mut mention = PersonNotification::new(
2974            PersonNotificationKind::Mention,
2975            t(60_000),
2976            ID_CHANNEL,
2977            ID_BOB,
2978        );
2979        mention.seq = 78;
2980        mention.space_id = Some(ID_SPACE);
2981        mention.message_id = Some(ID_MESSAGE);
2982        mention.from_external_id = Some("k2:principal:5b1c0000-0000-4000-8000-000000000004".into());
2983        mention.app_id = Some("atrium".into());
2984        mention.participant_app_ids = vec!["jobs".into()];
2985        mention.preview = Some("@bob can you check the deploy log?".into());
2986        let mut ring = PersonNotification::new(
2987            PersonNotificationKind::CallRing,
2988            t(120_000),
2989            ID_DM,
2990            ID_CAROL,
2991        );
2992        ring.seq = 80;
2993        ring.message_id = Some(ID_REPLY);
2994        ring.call_id = Some(ID_JOB);
2995        ring.from_external_id = Some("k2:principal:5b1c0000-0000-4000-8000-000000000016".into());
2996        let mut reply = PersonNotification::new(
2997            PersonNotificationKind::ReplyToMe,
2998            t(180_000),
2999            ID_CHANNEL,
3000            ID_BOB,
3001        );
3002        reply.seq = 82;
3003        reply.space_id = Some(ID_SPACE);
3004        reply.message_id = Some(ID_REPLY);
3005        reply.thread_root_id = Some(ID_MESSAGE);
3006        reply.from_external_id = Some("k2:principal:5b1c0000-0000-4000-8000-000000000004".into());
3007        reply.app_id = Some("atrium".into());
3008        let mut read =
3009            PersonNotification::new(PersonNotificationKind::Read, t(240_000), ID_CHANNEL, ID_ME);
3010        read.seq = 83;
3011        read.space_id = Some(ID_SPACE);
3012        read.message_id = Some(ID_REPLY);
3013        read.thread_root_id = Some(ID_MESSAGE);
3014        read.app_id = Some("atrium".into());
3015        let mut invite = PersonNotification::new(
3016            PersonNotificationKind::VoiceInvite,
3017            t(300_000),
3018            ID_OTHER_CHANNEL,
3019            ID_BOB,
3020        );
3021        invite.seq = 84;
3022        invite.space_id = Some(ID_SPACE);
3023        invite.invite_id = Some(ID_JOB);
3024        invite.expires_at = Some(t(600_000));
3025        invite.from_external_id = Some("k2:principal:5b1c0000-0000-4000-8000-000000000004".into());
3026        invite.app_id = Some("atrium".into());
3027        let full = PersonNotificationsPage::new(vec![mention, ring, reply, read, invite], 84, 90);
3028        let min = PersonNotificationsPage::new(vec![], 77, 77);
3029        vec![("full", full), ("min", min)]
3030    }
3031}
3032
3033impl Example for PersonNotificationsHead {
3034    fn examples() -> Vec<(&'static str, Self)> {
3035        vec![("full", PersonNotificationsHead::new(812))]
3036    }
3037}
3038
3039impl Example for CursorExpiredDetails {
3040    fn examples() -> Vec<(&'static str, Self)> {
3041        vec![(
3042            "full",
3043            CursorExpiredDetails {
3044                oldest_seq: 900,
3045                head: 950,
3046            },
3047        )]
3048    }
3049}
3050
3051impl Example for KeysMirrorSyncResponse {
3052    fn examples() -> Vec<(&'static str, Self)> {
3053        vec![
3054            (
3055                "ok",
3056                KeysMirrorSyncResponse {
3057                    kind: "dir".into(),
3058                    ok: true,
3059                    pushed: 1,
3060                    failed: 0,
3061                    repaired: 12,
3062                    deleted_shredded: 0,
3063                    unknown: 0,
3064                    error: None,
3065                    placement: None,
3066                    last_full_reconcile_ok_at: Some(t(0)),
3067                },
3068            ),
3069            (
3070                // The mount went down after an earlier good reconcile.
3071                "full",
3072                KeysMirrorSyncResponse {
3073                    kind: "dir".into(),
3074                    ok: false,
3075                    pushed: 0,
3076                    failed: 2,
3077                    repaired: 0,
3078                    deleted_shredded: 0,
3079                    unknown: 0,
3080                    error: Some(
3081                        "keyring mirror path /mnt/sew-keyring-mirror is not a mount point and holds no FORMAT of this install (is the mount down?); nothing written".into(),
3082                    ),
3083                    placement: Some("unmounted".into()),
3084                    last_full_reconcile_ok_at: Some(t(0)),
3085                },
3086            ),
3087        ]
3088    }
3089}
3090
3091impl Example for StartJobResponse {
3092    fn examples() -> Vec<(&'static str, Self)> {
3093        vec![("full", StartJobResponse { job_id: ID_JOB })]
3094    }
3095}
3096
3097impl Example for JobStatus {
3098    fn examples() -> Vec<(&'static str, Self)> {
3099        vec![
3100            (
3101                "full",
3102                JobStatus {
3103                    id: ID_JOB,
3104                    kind: "backup".into(),
3105                    state: JobState::Failed,
3106                    attempts: 2,
3107                    last_error: Some("disk_full".into()),
3108                    created_at: t(0),
3109                    finished_at: Some(t(90_000)),
3110                    result: Some(json!({"bundle_id": "20260927T031512Z", "bytes": 1_048_576})),
3111                },
3112            ),
3113            ("min", job_min()),
3114        ]
3115    }
3116}
3117
3118fn job_min() -> JobStatus {
3119    JobStatus {
3120        id: ID_JOB,
3121        kind: "backup".into(),
3122        state: JobState::Queued,
3123        attempts: 0,
3124        last_error: None,
3125        created_at: t(0),
3126        finished_at: None,
3127        result: None,
3128    }
3129}
3130
3131impl Example for JobsQuery {
3132    fn examples() -> Vec<(&'static str, Self)> {
3133        vec![
3134            (
3135                "full",
3136                JobsQuery {
3137                    state: Some(JobState::Dead),
3138                    kind: Some("backup".into()),
3139                    before: Some(ID_JOB),
3140                    limit: Some(20),
3141                },
3142            ),
3143            ("min", JobsQuery::default()),
3144        ]
3145    }
3146}
3147
3148impl Example for JobStatusPage {
3149    fn examples() -> Vec<(&'static str, Self)> {
3150        vec![(
3151            "full",
3152            Page {
3153                items: vec![job_min()],
3154                has_more: true,
3155            },
3156        )]
3157    }
3158}
3159
3160impl Example for OwnerSetResponse {
3161    fn examples() -> Vec<(&'static str, Self)> {
3162        vec![
3163            (
3164                "full",
3165                OwnerSetResponse {
3166                    owner_id: ID_CAROL,
3167                    previous_owner_id: Some(ID_ME),
3168                    changed: true,
3169                },
3170            ),
3171            (
3172                "min",
3173                OwnerSetResponse {
3174                    owner_id: ID_ME,
3175                    previous_owner_id: None,
3176                    changed: false,
3177                },
3178            ),
3179        ]
3180    }
3181}
3182
3183impl Example for PinResponse {
3184    fn examples() -> Vec<(&'static str, Self)> {
3185        vec![
3186            (
3187                "full",
3188                PinResponse {
3189                    agent_id: ID_CAROL,
3190                    person_id: Some(ID_ME),
3191                    changed: true,
3192                },
3193            ),
3194            (
3195                "min",
3196                PinResponse {
3197                    agent_id: ID_CAROL,
3198                    person_id: None,
3199                    changed: false,
3200                },
3201            ),
3202        ]
3203    }
3204}
3205
3206impl Example for PrincipalsQuery {
3207    fn examples() -> Vec<(&'static str, Self)> {
3208        vec![
3209            (
3210                "full",
3211                PrincipalsQuery {
3212                    after: Some(ID_ME),
3213                    limit: Some(200),
3214                    kind: Some(MemberKind::Agent),
3215                    external_id: Some(ext(WORKSPACE)),
3216                    username: Some(handle("morgan-assistant")),
3217                    include_deactivated: false,
3218                    compliance: Some(true),
3219                    include: Some(PrincipalsInclude::LinkGuests),
3220                },
3221            ),
3222            (
3223                "min",
3224                PrincipalsQuery {
3225                    after: None,
3226                    limit: None,
3227                    kind: None,
3228                    external_id: None,
3229                    username: None,
3230                    include_deactivated: true,
3231                    compliance: None,
3232                    include: None,
3233                },
3234            ),
3235        ]
3236    }
3237}
3238
3239impl Example for MgmtPrincipalPage {
3240    fn examples() -> Vec<(&'static str, Self)> {
3241        vec![(
3242            "full",
3243            Page {
3244                items: vec![
3245                    MgmtPrincipal {
3246                        member_id: ID_CAROL,
3247                        external_id: ext(WORKSPACE),
3248                        kind: MemberKind::Agent,
3249                        agent_kind: Some(AgentKind::Assistant),
3250                        assistant_of: Some(ext(PRINCIPAL)),
3251                        install_role: InstallRole::Member,
3252                        username: handle("morgan-assistant"),
3253                        display_name: "Morgan's assistant".into(),
3254                        email: Some("assistant@example.com".into()),
3255                        title: Some("Assistant".into()),
3256                        pronouns: Some("it/its".into()),
3257                        deactivated: true,
3258                        created_at: t(0),
3259                        deactivated_at: Some(t(60_000)),
3260                    },
3261                    MgmtPrincipal {
3262                        member_id: ID_ME,
3263                        external_id: ext(PRINCIPAL),
3264                        kind: MemberKind::Person,
3265                        agent_kind: None,
3266                        assistant_of: None,
3267                        install_role: InstallRole::Owner,
3268                        username: handle("morgan"),
3269                        display_name: "Morgan".into(),
3270                        email: None,
3271                        title: None,
3272                        pronouns: None,
3273                        deactivated: false,
3274                        created_at: t(0),
3275                        deactivated_at: None,
3276                    },
3277                ],
3278                has_more: false,
3279            },
3280        )]
3281    }
3282}
3283
3284// ---------------------------------------------------------------- mgmt/local
3285
3286fn local_user_response() -> LocalUserResponse {
3287    LocalUserResponse {
3288        member_id: ID_ME,
3289        username: handle("morgan"),
3290        install_role: InstallRole::Owner,
3291        deactivated: false,
3292        created: true,
3293        reactivated: false,
3294        changed: true,
3295        setup_link: Some(SetupLink {
3296            url: format!(
3297                "https://chat.example.com/setup#token=sewpw_{}",
3298                "z".repeat(43)
3299            ),
3300            expires_at: t(86_400_000),
3301        }),
3302    }
3303}
3304
3305impl Example for LocalUserCreateRequest {
3306    fn examples() -> Vec<(&'static str, Self)> {
3307        vec![
3308            (
3309                "full",
3310                LocalUserCreateRequest {
3311                    username: handle("bob"),
3312                    display_name: "Bob B".into(),
3313                    install_role: LocalRole::Admin,
3314                    email: Some("bob@example.com".into()),
3315                    setup_link: false,
3316                },
3317            ),
3318            (
3319                "min",
3320                LocalUserCreateRequest {
3321                    username: handle("bob"),
3322                    display_name: "Bob".into(),
3323                    install_role: LocalRole::Member,
3324                    email: None,
3325                    setup_link: true,
3326                },
3327            ),
3328        ]
3329    }
3330}
3331
3332impl Example for SetupLinkRequest {
3333    fn examples() -> Vec<(&'static str, Self)> {
3334        vec![
3335            (
3336                "full",
3337                SetupLinkRequest {
3338                    username: handle("morgan"),
3339                    owner: true,
3340                    display_name: Some("Morgan".into()),
3341                },
3342            ),
3343            (
3344                "min",
3345                SetupLinkRequest {
3346                    username: handle("bob"),
3347                    owner: false,
3348                    display_name: None,
3349                },
3350            ),
3351        ]
3352    }
3353}
3354
3355impl Example for LocalUserRef {
3356    fn examples() -> Vec<(&'static str, Self)> {
3357        vec![(
3358            "full",
3359            LocalUserRef {
3360                username: handle("bob"),
3361            },
3362        )]
3363    }
3364}
3365
3366impl Example for LocalRoleRequest {
3367    fn examples() -> Vec<(&'static str, Self)> {
3368        vec![(
3369            "full",
3370            LocalRoleRequest {
3371                username: handle("bob"),
3372                install_role: LocalSettableRole::Admin,
3373            },
3374        )]
3375    }
3376}
3377
3378impl Example for LocalUserResponse {
3379    fn examples() -> Vec<(&'static str, Self)> {
3380        let min = LocalUserResponse {
3381            setup_link: None,
3382            created: false,
3383            changed: false,
3384            install_role: InstallRole::Member,
3385            username: handle("bob"),
3386            member_id: ID_BOB,
3387            ..local_user_response()
3388        };
3389        vec![("full", local_user_response()), ("min", min)]
3390    }
3391}
3392
3393// ---------------------------------------------------------------- policy
3394
3395impl Example for Policies {
3396    fn examples() -> Vec<(&'static str, Self)> {
3397        let full = Policies {
3398            spaces_create: SpacesCreate::Members,
3399            channels_create_public_floor: ChannelCreateFloor::SpaceAdmins,
3400            channels_create_private_floor: ChannelCreateFloor::InstallAdmins,
3401            gifs_enabled: true,
3402            gifs_provider: Some("giphy".into()),
3403            gifs_api_key_ref: Some("secret:giphy".into()),
3404            meetings_enabled: true,
3405            meetings_privacy_contact: Some("privacy@example.com".into()),
3406            identity_managed_fields: Some(vec![
3407                ManagedProfileField::DisplayName,
3408                ManagedProfileField::Avatar,
3409            ]),
3410            ..Policies::default()
3411        };
3412        vec![("full", full), ("min", Policies::default())]
3413    }
3414}
3415
3416fn policy_patch_full() -> PolicyPatch {
3417    PolicyPatch {
3418        spaces_create: Some(SpacesCreate::Members),
3419        channels_create_public_floor: Some(ChannelCreateFloor::Perm),
3420        channels_create_private_floor: Some(ChannelCreateFloor::SpaceAdmins),
3421        channels_archive: Some(ArchiveWho::Managers),
3422        mentions_channel_max_members: Some(500),
3423        guests_invite: Some(GuestInvite::Perm),
3424        guests_dm_non_channel_mates: Some(true),
3425        messages_edit_window_s: Some(3_600),
3426        messages_delete_own: Some(false),
3427        gifs_enabled: Some(true),
3428        gifs_provider: Patch::Set("giphy".into()),
3429        gifs_api_key_ref: Patch::Set("secret:giphy".into()),
3430        link_previews_enabled: Some(false),
3431        files_max_bytes: Some(104_857_600),
3432        files_space_quota_bytes: Some(10_737_418_240),
3433        emoji_max_per_space: Some(1_000),
3434        retention_default_days: Some(365),
3435        private_space_admins_can_join: Some(true),
3436        presence_show_to_guests: Some(true),
3437        digest_enabled: Some(true),
3438        agents_allowed_in_dms: Some(false),
3439        agents_dm_with_box_people: Some(false),
3440        dm_read_receipts: Some(false),
3441        files_strip_image_location: Some(false),
3442        messages_deleted_purge_days: Some(30),
3443        guests_enabled: Some(false),
3444        notifications_default_level: Some(crate::api::notify::NotifyLevel::All),
3445        notifications_mgmt_preview: Some(true),
3446        digest_detail: Some(crate::api::notify::DigestDetail::Counts),
3447        calls_verification_code: Some(crate::e2ee::VerificationCode::Hidden),
3448        calls_dm_enabled: Some(false),
3449        calls_stats_beacon: Some(true),
3450        recording_enabled: Some(true),
3451        recording_dm_enabled: Some(false),
3452        recording_audio_default_days: Some(30),
3453        recording_audio_max_days: Some(365),
3454        recording_require_consent_to_join: Some(false),
3455        recording_required: Some(crate::recording::RecordingRequiredPolicy::MultiPerson),
3456        meetings_enabled: Some(true),
3457        meetings_create: Some(MeetingsCreate::Admins),
3458        meetings_max_participants: Some(100),
3459        meetings_max_duration_minutes: Some(240),
3460        meetings_grace_minutes: Some(10),
3461        meetings_link_guests: Some(false),
3462        meetings_privacy_contact: Patch::Set("privacy@example.com".into()),
3463        identity_managed_fields: Patch::Set(vec![
3464            ManagedProfileField::DisplayName,
3465            ManagedProfileField::Avatar,
3466        ]),
3467    }
3468}
3469
3470impl Example for PolicyPatch {
3471    fn examples() -> Vec<(&'static str, Self)> {
3472        vec![
3473            ("full", policy_patch_full()),
3474            ("min", PolicyPatch::default()),
3475            (
3476                "clear_gifs",
3477                PolicyPatch {
3478                    gifs_enabled: Some(false),
3479                    gifs_provider: Patch::Clear,
3480                    gifs_api_key_ref: Patch::Clear,
3481                    ..PolicyPatch::default()
3482                },
3483            ),
3484        ]
3485    }
3486}
3487
3488impl Example for PoliciesResponse {
3489    fn examples() -> Vec<(&'static str, Self)> {
3490        vec![(
3491            "full",
3492            PoliciesResponse {
3493                policies: Policies::default(),
3494            },
3495        )]
3496    }
3497}
3498
3499impl Example for SetPoliciesRequest {
3500    fn examples() -> Vec<(&'static str, Self)> {
3501        vec![
3502            (
3503                "full",
3504                SetPoliciesRequest {
3505                    changes: policy_patch_full(),
3506                },
3507            ),
3508            (
3509                "gifs_on",
3510                SetPoliciesRequest {
3511                    changes: PolicyPatch {
3512                        gifs_enabled: Some(true),
3513                        ..PolicyPatch::default()
3514                    },
3515                },
3516            ),
3517        ]
3518    }
3519}
3520
3521// ---------------------------------------------------------------- audit
3522
3523impl Example for AuditEvent {
3524    fn examples() -> Vec<(&'static str, Self)> {
3525        let full = AuditEvent {
3526            id: ID_AUDIT,
3527            at: t(0),
3528            actor: Actor {
3529                member_id: Some(ID_CAROL),
3530                kind: ActorKind::Agent,
3531                via: Some(ActorVia {
3532                    system: "k2".into(),
3533                    agent: "7c9e6679-7425-40de-944b-e07fc1f90ae7".into(),
3534                    k2_session: "skn_4f1c2a".into(),
3535                }),
3536                on_behalf_of: Some(ID_ME),
3537                peer_uid: Some(1_001),
3538                ip: Some("127.0.0.1".into()),
3539            },
3540            action: Action::ChannelArchive,
3541            target: Some(AuditTarget {
3542                kind: "channel".into(),
3543                id: ID_CHANNEL,
3544            }),
3545            space_id: Some(ID_SPACE),
3546            channel_id: Some(ID_CHANNEL),
3547            result: AuditResult::Ok,
3548            details: obj(json!({"old": {"archived": false}, "new": {"archived": true}})),
3549        };
3550        let min = AuditEvent {
3551            id: ID_AUDIT,
3552            at: t(0),
3553            actor: Actor {
3554                member_id: None,
3555                kind: ActorKind::System,
3556                via: None,
3557                on_behalf_of: None,
3558                peer_uid: None,
3559                ip: None,
3560            },
3561            action: Action::LoginFail,
3562            target: None,
3563            space_id: None,
3564            channel_id: None,
3565            result: AuditResult::Denied,
3566            details: Map::new(),
3567        };
3568        vec![("full", full), ("min", min)]
3569    }
3570}
3571
3572// ---------------------------------------------------------------- when
3573
3574impl Example for When {
3575    fn examples() -> Vec<(&'static str, Self)> {
3576        vec![
3577            ("at", When::At { at: t(3_600_000) }),
3578            (
3579                "local",
3580                When::Local {
3581                    date_time: "2026-10-01T09:00".into(),
3582                    timezone: Some("America/Los_Angeles".into()),
3583                },
3584            ),
3585            (
3586                "local_min",
3587                When::Local {
3588                    date_time: "2026-10-01T09:00".into(),
3589                    timezone: None,
3590                },
3591            ),
3592            ("in", When::In { ms: 1_800_000 }),
3593        ]
3594    }
3595}
3596
3597// ---- Install inputs as JSON
3598
3599impl Example for crate::install::InstallInputs {
3600    fn examples() -> Vec<(&'static str, Self)> {
3601        vec![
3602            (
3603                "full",
3604                crate::install::InstallInputs {
3605                    provider: Some("k2".into()),
3606                    k2_jwks_url: Some("http://127.0.0.1:7300/v1/chat/jwks".into()),
3607                    profile: Some("shared".into()),
3608                    pg_major: Some(16),
3609                    master_key_from: Some("/run/k2/sew/master.key".into()),
3610                    cred_mode: Some("encrypted".into()),
3611                    mgmt_users: vec!["k2".into()],
3612                    mgmt_allow_uids: Some(vec![988]),
3613                },
3614            ),
3615            ("min", crate::install::InstallInputs::default()),
3616        ]
3617    }
3618}
3619
3620impl Example for crate::install::MediaInstallInputs {
3621    fn examples() -> Vec<(&'static str, Self)> {
3622        vec![
3623            (
3624                "full",
3625                crate::install::MediaInstallInputs {
3626                    tarball: Some("/var/lib/sew/staging/sew-media.tar.zst".into()),
3627                    public_url: Some("wss://voice.example.com".into()),
3628                    node_ip: Some("203.0.113.7".into()),
3629                    stun_servers: vec!["stun.example.net:3478".into()],
3630                    allow_private_node_ip: Some(false),
3631                    udp_port: Some(7882),
3632                    tcp_port: Some(7881),
3633                    bind_v4: Some("0.0.0.0".into()),
3634                    bind_v6: Some(String::new()),
3635                    turn_tls: Some("direct".into()),
3636                    turn_domain: Some("turn.example.com".into()),
3637                    turn_cert: Some("/var/lib/sew/staging/turn-fullchain.pem".into()),
3638                    turn_key: Some("/var/lib/sew/staging/turn-key.pem".into()),
3639                    turn_advertise_port: Some(5349),
3640                    turn_proxy_protocol: Some("v2".into()),
3641                    turn_plain: vec!["udp".into()],
3642                    profile: Some("shared".into()),
3643                    cred_mode: Some("encrypted".into()),
3644                    sysctl: Some("apply".into()),
3645                    relay_only: Some(false),
3646                    turn_trusted_cidrs: vec!["127.0.0.1/32".into(), "::1/128".into()],
3647                },
3648            ),
3649            ("min", crate::install::MediaInstallInputs::default()),
3650        ]
3651    }
3652}
3653
3654// ---- Spaces over mgmt
3655
3656impl Example for MgmtSpaceCreateRequest {
3657    fn examples() -> Vec<(&'static str, Self)> {
3658        let full = MgmtSpaceCreateRequest {
3659            slug: slug("atrium-lobby"),
3660            name: "Atrium lobby".into(),
3661            owner: Some(ExternalId::service_owner("atrium")),
3662            managers: vec![ext(WORKSPACE), ext(PRINCIPAL)],
3663            app_id: Some("atrium".into()),
3664            hidden: true,
3665            governance: None,
3666        };
3667        let min = MgmtSpaceCreateRequest {
3668            slug: slug("ops"),
3669            name: "Ops".into(),
3670            owner: Some(ext(PRINCIPAL)),
3671            managers: vec![],
3672            app_id: None,
3673            hidden: false,
3674            governance: None,
3675        };
3676        // The server-governed Space.
3677        let admin = MgmtSpaceCreateRequest {
3678            slug: slug("k5-admin"),
3679            name: "K5 Space".into(),
3680            owner: Some(ExternalId::K2Server),
3681            managers: vec![],
3682            app_id: None,
3683            hidden: false,
3684            governance: Some(SpaceGovernance::Server),
3685        };
3686        vec![("full", full), ("min", min), ("full_admin", admin)]
3687    }
3688}
3689
3690impl Example for MgmtSpaceResponse {
3691    fn examples() -> Vec<(&'static str, Self)> {
3692        let full = MgmtSpaceResponse {
3693            space_id: ID_SPACE,
3694            slug: slug("atrium-lobby"),
3695            name: "Atrium lobby".into(),
3696            owner_member_id: ID_ME,
3697            app_id: Some("atrium".into()),
3698            created: true,
3699            manager_role_id: Some(ID_ROLE),
3700            manager_member_ids: vec![ID_BOB, ID_CAROL],
3701            hidden: true,
3702            governance: SpaceGovernance::App,
3703        };
3704        let min = MgmtSpaceResponse {
3705            app_id: None,
3706            created: false,
3707            manager_role_id: None,
3708            manager_member_ids: vec![],
3709            hidden: false,
3710            governance: SpaceGovernance::Sew,
3711            ..full.clone()
3712        };
3713        // The server-governed Space.
3714        let admin = MgmtSpaceResponse {
3715            slug: slug("k5-admin"),
3716            name: "K5 Space".into(),
3717            created: true,
3718            governance: SpaceGovernance::Server,
3719            ..min.clone()
3720        };
3721        vec![("full", full), ("min", min), ("full_admin", admin)]
3722    }
3723}
3724
3725impl Example for MgmtSpaceBindRequest {
3726    fn examples() -> Vec<(&'static str, Self)> {
3727        vec![(
3728            "full",
3729            MgmtSpaceBindRequest {
3730                space_id: ID_SPACE,
3731                app_id: "atrium".into(),
3732            },
3733        )]
3734    }
3735}
3736
3737impl Example for MgmtSpaceUnbindRequest {
3738    fn examples() -> Vec<(&'static str, Self)> {
3739        vec![(
3740            "full",
3741            MgmtSpaceUnbindRequest {
3742                space_id: ID_SPACE,
3743                app_id: "atrium".into(),
3744            },
3745        )]
3746    }
3747}
3748
3749impl Example for MgmtSpaceReleaseRequest {
3750    fn examples() -> Vec<(&'static str, Self)> {
3751        vec![(
3752            "full",
3753            MgmtSpaceReleaseRequest {
3754                space_id: ID_SPACE,
3755                confirm: true,
3756            },
3757        )]
3758    }
3759}
3760
3761impl Example for MgmtSpaceOrphanResponse {
3762    fn examples() -> Vec<(&'static str, Self)> {
3763        let full = MgmtSpaceOrphanResponse {
3764            space_id: ID_SPACE,
3765            app_id: Some("atrium".into()),
3766            orphaned_from: Some("atrium".into()),
3767            changed: true,
3768        };
3769        let unbound = MgmtSpaceOrphanResponse {
3770            app_id: None,
3771            ..full.clone()
3772        };
3773        let released = MgmtSpaceOrphanResponse {
3774            app_id: None,
3775            orphaned_from: None,
3776            changed: false,
3777            ..full.clone()
3778        };
3779        vec![("full", full), ("unbound", unbound), ("released", released)]
3780    }
3781}
3782
3783impl Example for MgmtHomeClientRequest {
3784    fn examples() -> Vec<(&'static str, Self)> {
3785        vec![
3786            (
3787                "full",
3788                MgmtHomeClientRequest {
3789                    app_id: Some("atrium".into()),
3790                    approval: Some(OwnerApproval::OwnerPass { pass: PASS.into() }),
3791                },
3792            ),
3793            (
3794                "none",
3795                MgmtHomeClientRequest {
3796                    app_id: None,
3797                    approval: Some(OwnerApproval::OwnerPassword {
3798                        password: "correct horse battery staple".into(),
3799                    }),
3800                },
3801            ),
3802        ]
3803    }
3804}
3805
3806impl Example for MgmtHomeClient {
3807    fn examples() -> Vec<(&'static str, Self)> {
3808        vec![
3809            (
3810                "full",
3811                MgmtHomeClient {
3812                    app_id: Some("atrium".into()),
3813                },
3814            ),
3815            ("none", MgmtHomeClient { app_id: None }),
3816        ]
3817    }
3818}
3819
3820impl Example for MgmtAppSettingsRequest {
3821    fn examples() -> Vec<(&'static str, Self)> {
3822        vec![
3823            (
3824                "full",
3825                MgmtAppSettingsRequest {
3826                    hidden_from_home: Some(true),
3827                    display_name: Patch::Set("Jobs".into()),
3828                    origin: Patch::Set("wss://jobs.example.com".into()),
3829                    max_level: Some(SpaceLevel::Admin),
3830                    uploads: Some(false),
3831                    origins: Patch::Set(vec![
3832                        "wss://jobs.acme.example".into(),
3833                        "wss://jobs.example.com:8443".into(),
3834                    ]),
3835                    recording: Some(mgmt_recordings::app_recording_request_full()),
3836                },
3837            ),
3838            (
3839                "clear",
3840                MgmtAppSettingsRequest {
3841                    hidden_from_home: None,
3842                    display_name: Patch::Clear,
3843                    origin: Patch::Clear,
3844                    max_level: None,
3845                    uploads: None,
3846                    origins: Patch::Clear,
3847                    recording: None,
3848                },
3849            ),
3850            ("min", MgmtAppSettingsRequest::default()),
3851        ]
3852    }
3853}
3854
3855impl Example for MgmtAppSettings {
3856    fn examples() -> Vec<(&'static str, Self)> {
3857        vec![
3858            (
3859                "full",
3860                MgmtAppSettings {
3861                    app_id: "jobs".into(),
3862                    hidden_from_home: true,
3863                    display_name: Some("Jobs".into()),
3864                    origin: Some("wss://jobs.example.com".into()),
3865                    max_level: SpaceLevel::Admin,
3866                    uploads: false,
3867                    origins: vec![
3868                        "wss://jobs.acme.example".into(),
3869                        "wss://jobs.example.com:8443".into(),
3870                    ],
3871                    recording: mgmt_recordings::app_recording_full(),
3872                },
3873            ),
3874            (
3875                "min",
3876                MgmtAppSettings {
3877                    app_id: "jobs".into(),
3878                    hidden_from_home: false,
3879                    display_name: None,
3880                    origin: None,
3881                    max_level: SpaceLevel::Moderator,
3882                    uploads: true,
3883                    origins: Vec::new(),
3884                    recording: MgmtAppRecording::new(),
3885                },
3886            ),
3887        ]
3888    }
3889}
3890
3891impl Example for MgmtSpaceSettingsRequest {
3892    fn examples() -> Vec<(&'static str, Self)> {
3893        vec![
3894            (
3895                "full",
3896                MgmtSpaceSettingsRequest {
3897                    app_id: Some("jobs".into()),
3898                    private: Some(true),
3899                    governance: Some(SpaceGovernance::App),
3900                    recording_start_level: Patch::Set(
3901                        crate::recording::RecordingStartLevel::Moderator,
3902                    ),
3903                    recording_required: Patch::Set(true),
3904                },
3905            ),
3906            ("min", MgmtSpaceSettingsRequest::default()),
3907        ]
3908    }
3909}
3910
3911impl Example for MgmtSpaceSettings {
3912    fn examples() -> Vec<(&'static str, Self)> {
3913        vec![
3914            (
3915                "full",
3916                MgmtSpaceSettings {
3917                    space_id: ID_SPACE,
3918                    app_id: Some("jobs".into()),
3919                    private: true,
3920                    join_policy: SpaceJoinPolicy::Invite,
3921                    governance: SpaceGovernance::App,
3922                    recording_start_level: Some(crate::recording::RecordingStartLevel::Moderator),
3923                    recording_required: Some(true),
3924                },
3925            ),
3926            (
3927                "min",
3928                MgmtSpaceSettings {
3929                    space_id: ID_SPACE,
3930                    app_id: None,
3931                    private: false,
3932                    join_policy: SpaceJoinPolicy::Open,
3933                    governance: SpaceGovernance::Sew,
3934                    recording_start_level: None,
3935                    recording_required: None,
3936                },
3937            ),
3938        ]
3939    }
3940}
3941
3942impl Example for MgmtSpaceApps {
3943    fn examples() -> Vec<(&'static str, Self)> {
3944        vec![
3945            (
3946                "full",
3947                MgmtSpaceApps {
3948                    space_id: ID_SPACE,
3949                    governance: SpaceGovernance::App,
3950                    items: vec![MgmtSpaceApp {
3951                        app_id: "jobs".into(),
3952                        role: MgmtSpaceAppRole::Governing,
3953                    }],
3954                },
3955            ),
3956            (
3957                "unbound",
3958                MgmtSpaceApps {
3959                    space_id: ID_SPACE,
3960                    governance: SpaceGovernance::Sew,
3961                    items: vec![],
3962                },
3963            ),
3964        ]
3965    }
3966}
3967
3968impl Example for MgmtSpaceAppLinkRequest {
3969    fn examples() -> Vec<(&'static str, Self)> {
3970        vec![(
3971            "full",
3972            MgmtSpaceAppLinkRequest {
3973                governing_app_id: "jobs".into(),
3974                app_id: "home".into(),
3975            },
3976        )]
3977    }
3978}
3979
3980impl Example for MgmtSpaceAppsChange {
3981    fn examples() -> Vec<(&'static str, Self)> {
3982        vec![
3983            (
3984                "full",
3985                MgmtSpaceAppsChange {
3986                    space_id: ID_SPACE,
3987                    governance: SpaceGovernance::App,
3988                    items: vec![
3989                        MgmtSpaceApp {
3990                            app_id: "jobs".into(),
3991                            role: MgmtSpaceAppRole::Governing,
3992                        },
3993                        MgmtSpaceApp {
3994                            app_id: "home".into(),
3995                            role: MgmtSpaceAppRole::Participant,
3996                        },
3997                    ],
3998                    changed: true,
3999                },
4000            ),
4001            (
4002                "unlinked",
4003                MgmtSpaceAppsChange {
4004                    space_id: ID_SPACE,
4005                    governance: SpaceGovernance::Sew,
4006                    items: vec![MgmtSpaceApp {
4007                        app_id: "jobs".into(),
4008                        role: MgmtSpaceAppRole::Governing,
4009                    }],
4010                    changed: false,
4011                },
4012            ),
4013        ]
4014    }
4015}
4016
4017impl Example for MgmtAppSpacesQuery {
4018    fn examples() -> Vec<(&'static str, Self)> {
4019        vec![
4020            (
4021                "full",
4022                MgmtAppSpacesQuery {
4023                    after: Some(ID_SPACE),
4024                    limit: Some(500),
4025                },
4026            ),
4027            ("min", MgmtAppSpacesQuery::default()),
4028        ]
4029    }
4030}
4031
4032impl Example for MgmtAppSpaces {
4033    fn examples() -> Vec<(&'static str, Self)> {
4034        vec![
4035            (
4036                "full",
4037                MgmtAppSpaces {
4038                    app_id: "home".into(),
4039                    items: vec![MgmtAppSpace {
4040                        space_id: ID_SPACE,
4041                        role: MgmtSpaceAppRole::Participant,
4042                    }],
4043                    next: Some(ID_SPACE),
4044                },
4045            ),
4046            (
4047                "last",
4048                MgmtAppSpaces {
4049                    app_id: "home".into(),
4050                    items: vec![],
4051                    next: None,
4052                },
4053            ),
4054        ]
4055    }
4056}
4057
4058impl Example for MgmtSpaceMembersAddRequest {
4059    fn examples() -> Vec<(&'static str, Self)> {
4060        let full = MgmtSpaceMembersAddRequest {
4061            space_id: ID_SPACE,
4062            app_id: Some("atrium".into()),
4063            external_ids: vec![ext(PRINCIPAL), ext(CONNECT_USER)],
4064        };
4065        let min = MgmtSpaceMembersAddRequest {
4066            app_id: None,
4067            external_ids: vec![ext(PRINCIPAL)],
4068            ..full.clone()
4069        };
4070        vec![("full", full), ("min", min)]
4071    }
4072}
4073
4074impl Example for MgmtSpaceMembersAddResponse {
4075    fn examples() -> Vec<(&'static str, Self)> {
4076        vec![(
4077            "full",
4078            MgmtSpaceMembersAddResponse {
4079                added: vec![MgmtSpaceMemberRef {
4080                    external_id: ext(PRINCIPAL),
4081                    member_id: ID_BOB,
4082                }],
4083                already: vec![MgmtSpaceMemberRef {
4084                    external_id: ExternalId::K2Owner,
4085                    member_id: ID_ME,
4086                }],
4087                skipped: vec![ID_CAROL],
4088                not_added: vec![MgmtSpaceNotAdded {
4089                    external_id: ext(CONNECT_USER),
4090                    reason: MgmtSpaceNotAddedReason::NotProvisioned,
4091                }],
4092            },
4093        )]
4094    }
4095}
4096
4097impl Example for MgmtChannelCreateRequest {
4098    fn examples() -> Vec<(&'static str, Self)> {
4099        let full = MgmtChannelCreateRequest {
4100            space_id: ID_SPACE,
4101            app_id: Some("atrium".into()),
4102            slug: slug("crew"),
4103            name: "Crew".into(),
4104            private: true,
4105            members: vec![ext(PRINCIPAL).into(), MgmtMemberRef::Member(ID_BOB)],
4106            kind: Some(ChannelType::Voice),
4107            user_limit: Some(12),
4108            members_can_leave: true,
4109        };
4110        let min = MgmtChannelCreateRequest {
4111            slug: slug("general"),
4112            name: "General".into(),
4113            private: false,
4114            members: vec![],
4115            kind: None,
4116            user_limit: None,
4117            members_can_leave: false,
4118            ..full.clone()
4119        };
4120        vec![("full", full), ("min", min)]
4121    }
4122}
4123
4124impl Example for MgmtChannelCreateResponse {
4125    fn examples() -> Vec<(&'static str, Self)> {
4126        let full = MgmtChannelCreateResponse {
4127            channel_id: ID_CHANNEL,
4128            space_id: ID_SPACE,
4129            slug: slug("crew"),
4130            name: "Crew".into(),
4131            private: true,
4132            kind: ChannelType::Voice,
4133            user_limit: Some(12),
4134            members_can_leave: true,
4135            created: true,
4136            added: vec![MgmtSpaceMemberRef {
4137                external_id: ext(PRINCIPAL),
4138                member_id: ID_BOB,
4139            }],
4140            already: vec![MgmtSpaceMemberRef {
4141                external_id: ExternalId::K2Owner,
4142                member_id: ID_ME,
4143            }],
4144            skipped: vec![ID_CAROL],
4145            not_added: vec![MgmtChannelNotAdded {
4146                member: ext(CONNECT_USER).into(),
4147                reason: MgmtChannelNotAddedReason::NotProvisioned,
4148            }],
4149        };
4150        let min = MgmtChannelCreateResponse {
4151            slug: slug("general"),
4152            name: "General".into(),
4153            private: false,
4154            created: false,
4155            added: vec![],
4156            already: vec![],
4157            skipped: vec![],
4158            not_added: vec![],
4159            kind: ChannelType::Text,
4160            user_limit: None,
4161            members_can_leave: false,
4162            ..full.clone()
4163        };
4164        vec![("full", full), ("min", min)]
4165    }
4166}
4167
4168impl Example for MgmtChannelMemberRequest {
4169    fn examples() -> Vec<(&'static str, Self)> {
4170        let full = MgmtChannelMemberRequest {
4171            app_id: Some("jobs".into()),
4172            external_id: ext(PRINCIPAL),
4173        };
4174        let min = MgmtChannelMemberRequest {
4175            app_id: None,
4176            external_id: ext(CONNECT_USER),
4177        };
4178        vec![("full", full), ("min", min)]
4179    }
4180}
4181
4182impl Example for MgmtChannelMemberResponse {
4183    fn examples() -> Vec<(&'static str, Self)> {
4184        let full = MgmtChannelMemberResponse {
4185            channel_id: ID_CHANNEL,
4186            space_id: ID_SPACE,
4187            external_id: ext(PRINCIPAL),
4188            member_id: ID_BOB,
4189            changed: true,
4190        };
4191        let unchanged = MgmtChannelMemberResponse {
4192            changed: false,
4193            ..full.clone()
4194        };
4195        vec![("full", full), ("full_unchanged", unchanged)]
4196    }
4197}
4198
4199impl Example for MgmtBoxUsersDetails {
4200    fn examples() -> Vec<(&'static str, Self)> {
4201        vec![(
4202            "full",
4203            MgmtBoxUsersDetails {
4204                reason: "box_users_present".into(),
4205                field: "governance".into(),
4206                external_ids: vec![ExternalId::K2Connect(
4207                    "0b8f2f52-1111-4222-8333-944445555666".into(),
4208                )],
4209            },
4210        )]
4211    }
4212}
4213
4214impl Example for MgmtChannelTypeMismatchDetails {
4215    fn examples() -> Vec<(&'static str, Self)> {
4216        vec![(
4217            "full",
4218            MgmtChannelTypeMismatchDetails {
4219                reason: "channel_type_mismatch".into(),
4220                field: "type".into(),
4221                existing_type: ChannelType::Voice,
4222            },
4223        )]
4224    }
4225}
4226
4227impl Example for MgmtChannelBulkRequest {
4228    fn examples() -> Vec<(&'static str, Self)> {
4229        let full = MgmtChannelBulkRequest {
4230            space_id: ID_SPACE,
4231            app_id: Some("jobs".into()),
4232            ops: vec![
4233                MgmtChannelOp::Ensure {
4234                    slug: slug("crew"),
4235                    name: "Crew".into(),
4236                    private: true,
4237                    kind: Some(ChannelType::Voice),
4238                    user_limit: Some(12),
4239                    members_can_leave: true,
4240                },
4241                MgmtChannelOp::Ensure {
4242                    slug: slug("general"),
4243                    name: "General".into(),
4244                    private: false,
4245                    kind: None,
4246                    user_limit: None,
4247                    members_can_leave: false,
4248                },
4249                MgmtChannelOp::Update {
4250                    channel_id: ID_CHANNEL,
4251                    members_can_leave: Some(false),
4252                },
4253                MgmtChannelOp::Rename {
4254                    channel_id: ID_CHANNEL,
4255                    name: "Night crew".into(),
4256                },
4257                MgmtChannelOp::Archive {
4258                    channel_id: ID_CHANNEL,
4259                },
4260                MgmtChannelOp::Unarchive {
4261                    channel_id: ID_CHANNEL,
4262                },
4263            ],
4264        };
4265        vec![("full", full)]
4266    }
4267}
4268
4269impl Example for MgmtChannelBulkResponse {
4270    fn examples() -> Vec<(&'static str, Self)> {
4271        let ok = |op, channel_id, created, changed| MgmtChannelOpResult {
4272            op,
4273            ok: true,
4274            channel_id: Some(channel_id),
4275            created,
4276            changed,
4277            error: None,
4278        };
4279        let mut mismatch = ApiError::new(
4280            Code::Conflict,
4281            "a channel of another type holds this slug in the Space",
4282        );
4283        mismatch
4284            .details
4285            .insert("reason".into(), json!("channel_type_mismatch"));
4286        mismatch.details.insert("field".into(), json!("type"));
4287        mismatch
4288            .details
4289            .insert("existing_type".into(), json!("text"));
4290        let full = MgmtChannelBulkResponse {
4291            space_id: ID_SPACE,
4292            results: vec![
4293                MgmtChannelOpResult {
4294                    op: MgmtChannelOpKind::Ensure,
4295                    ok: false,
4296                    channel_id: None,
4297                    created: None,
4298                    changed: None,
4299                    error: Some(mismatch),
4300                },
4301                ok(MgmtChannelOpKind::Ensure, ID_CHANNEL, Some(false), None),
4302                ok(MgmtChannelOpKind::Rename, ID_CHANNEL, None, Some(true)),
4303                ok(MgmtChannelOpKind::Archive, ID_CHANNEL, None, Some(true)),
4304                ok(MgmtChannelOpKind::Unarchive, ID_CHANNEL, None, Some(false)),
4305                ok(MgmtChannelOpKind::Update, ID_CHANNEL, None, Some(true)),
4306            ],
4307        };
4308        vec![("full", full)]
4309    }
4310}
4311
4312impl Example for AppQuotas {
4313    fn examples() -> Vec<(&'static str, Self)> {
4314        let full = AppQuotas {
4315            spaces_max: Some(10),
4316            channels_per_space_max: Some(50),
4317            members_per_space_max: Some(500),
4318            file_bytes_max: Some(10_737_418_240),
4319            call_participants_max: Some(25),
4320            messages_per_min: Some(600),
4321        };
4322        vec![("full", full), ("min", AppQuotas::default())]
4323    }
4324}
4325
4326impl Example for AppQuotasResponse {
4327    fn examples() -> Vec<(&'static str, Self)> {
4328        let full = AppQuotasResponse {
4329            app_id: "atrium".into(),
4330            quotas: AppQuotas {
4331                spaces_max: Some(10),
4332                channels_per_space_max: Some(50),
4333                members_per_space_max: Some(500),
4334                file_bytes_max: Some(10_737_418_240),
4335                call_participants_max: Some(25),
4336                messages_per_min: Some(600),
4337            },
4338            used: AppQuotaUsage {
4339                spaces_max: 2,
4340                channels_per_space_max: 7,
4341                members_per_space_max: 41,
4342                file_bytes_max: 52_428_800,
4343                call_participants_max: 3,
4344                messages_per_min: 12,
4345            },
4346            changed: Some(true),
4347        };
4348        let min = AppQuotasResponse {
4349            quotas: AppQuotas::default(),
4350            used: AppQuotaUsage::default(),
4351            changed: None,
4352            ..full.clone()
4353        };
4354        vec![("full", full), ("min", min)]
4355    }
4356}
4357
4358impl Example for AppQuotaDetails {
4359    fn examples() -> Vec<(&'static str, Self)> {
4360        let full = AppQuotaDetails {
4361            quota: QUOTA_MESSAGES_PER_MIN.into(),
4362            limit: 600,
4363            used: 600,
4364            app_id: "atrium".into(),
4365            retry_after_ms: Some(100),
4366        };
4367        let min = AppQuotaDetails {
4368            quota: QUOTA_CHANNELS_PER_SPACE_MAX.into(),
4369            limit: 50,
4370            used: 50,
4371            retry_after_ms: None,
4372            ..full.clone()
4373        };
4374        vec![("full", full), ("min", min)]
4375    }
4376}
4377
4378impl Example for MgmtSpaceMemberRemoveRequest {
4379    fn examples() -> Vec<(&'static str, Self)> {
4380        let full = MgmtSpaceMemberRemoveRequest {
4381            space_id: ID_SPACE,
4382            app_id: Some("atrium".into()),
4383            external_id: ext(PRINCIPAL),
4384        };
4385        let min = MgmtSpaceMemberRemoveRequest {
4386            app_id: None,
4387            ..full.clone()
4388        };
4389        vec![("full", full), ("min", min)]
4390    }
4391}
4392
4393impl Example for MgmtSpaceMemberRemoveResponse {
4394    fn examples() -> Vec<(&'static str, Self)> {
4395        vec![("full", MgmtSpaceMemberRemoveResponse { removed: true })]
4396    }
4397}
4398
4399// ---- Backups over mgmt
4400
4401impl Example for MgmtBackupList {
4402    fn examples() -> Vec<(&'static str, Self)> {
4403        vec![(
4404            "full",
4405            MgmtBackupList {
4406                items: vec![MgmtBackup {
4407                    id: "20260927T031512Z".into(),
4408                    kind: "manual".into(),
4409                    created_at: t(0),
4410                    bytes: 52_428_800,
4411                    schema_version: 920_001,
4412                    sew_version: "0.1.0".into(),
4413                }],
4414            },
4415        )]
4416    }
4417}
4418
4419impl Example for BackupJobResult {
4420    fn examples() -> Vec<(&'static str, Self)> {
4421        let full = BackupJobResult {
4422            id: "20260927T031512Z".into(),
4423            bytes: 52_428_800,
4424            duration_ms: 4_210,
4425            linked: 1_200,
4426            copied: 3,
4427            pruned: vec!["20260920T031502Z".into()],
4428        };
4429        let min = BackupJobResult {
4430            pruned: vec![],
4431            ..full.clone()
4432        };
4433        vec![("full", full), ("min", min)]
4434    }
4435}