1pub mod grant_verifications;
9pub mod list_verifications;
10pub mod revoke_verifications;
11
12
13#[allow(unused_imports)]
14use alloc::collections::BTreeMap;
15
16#[allow(unused_imports)]
17use core::marker::PhantomData;
18use jacquard_common::CowStr;
19
20#[allow(unused_imports)]
21use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
22use jacquard_common::types::string::{Did, Handle, AtUri, Datetime};
23use jacquard_common::types::value::Data;
24use jacquard_derive::{IntoStatic, lexicon, open_union};
25use jacquard_lexicon::lexicon::LexiconDoc;
26use jacquard_lexicon::schema::LexiconSchema;
27
28#[allow(unused_imports)]
29use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
30use serde::{Serialize, Deserialize};
31use crate::tools_ozone::moderation::RepoViewDetail;
32use crate::tools_ozone::moderation::RepoViewNotFound;
33#[lexicon]
36#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
37#[serde(rename_all = "camelCase")]
38pub struct VerificationView<'a> {
39 pub created_at: Datetime,
41 #[serde(borrow)]
43 pub display_name: CowStr<'a>,
44 #[serde(borrow)]
46 pub handle: Handle<'a>,
47 #[serde(borrow)]
49 pub issuer: Did<'a>,
50 #[serde(skip_serializing_if = "Option::is_none")]
51 #[serde(borrow)]
52 pub issuer_profile: Option<Data<'a>>,
53 #[serde(skip_serializing_if = "Option::is_none")]
54 #[serde(borrow)]
55 pub issuer_repo: Option<VerificationViewIssuerRepo<'a>>,
56 #[serde(skip_serializing_if = "Option::is_none")]
58 #[serde(borrow)]
59 pub revoke_reason: Option<CowStr<'a>>,
60 #[serde(skip_serializing_if = "Option::is_none")]
62 pub revoked_at: Option<Datetime>,
63 #[serde(skip_serializing_if = "Option::is_none")]
65 #[serde(borrow)]
66 pub revoked_by: Option<Did<'a>>,
67 #[serde(borrow)]
69 pub subject: Did<'a>,
70 #[serde(skip_serializing_if = "Option::is_none")]
71 #[serde(borrow)]
72 pub subject_profile: Option<Data<'a>>,
73 #[serde(skip_serializing_if = "Option::is_none")]
74 #[serde(borrow)]
75 pub subject_repo: Option<VerificationViewSubjectRepo<'a>>,
76 #[serde(borrow)]
78 pub uri: AtUri<'a>,
79}
80
81
82#[open_union]
83#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
84#[serde(tag = "$type", bound(deserialize = "'de: 'a"))]
85pub enum VerificationViewIssuerRepo<'a> {
86 #[serde(rename = "tools.ozone.moderation.defs#repoViewDetail")]
87 RepoViewDetail(Box<RepoViewDetail<'a>>),
88 #[serde(rename = "tools.ozone.moderation.defs#repoViewNotFound")]
89 RepoViewNotFound(Box<RepoViewNotFound<'a>>),
90}
91
92
93#[open_union]
94#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
95#[serde(tag = "$type", bound(deserialize = "'de: 'a"))]
96pub enum VerificationViewSubjectRepo<'a> {
97 #[serde(rename = "tools.ozone.moderation.defs#repoViewDetail")]
98 RepoViewDetail(Box<RepoViewDetail<'a>>),
99 #[serde(rename = "tools.ozone.moderation.defs#repoViewNotFound")]
100 RepoViewNotFound(Box<RepoViewNotFound<'a>>),
101}
102
103impl<'a> LexiconSchema for VerificationView<'a> {
104 fn nsid() -> &'static str {
105 "tools.ozone.verification.defs"
106 }
107 fn def_name() -> &'static str {
108 "verificationView"
109 }
110 fn lexicon_doc() -> LexiconDoc<'static> {
111 lexicon_doc_tools_ozone_verification_defs()
112 }
113 fn validate(&self) -> Result<(), ConstraintError> {
114 Ok(())
115 }
116}
117
118pub mod verification_view_state {
119
120 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
121 #[allow(unused)]
122 use ::core::marker::PhantomData;
123 mod sealed {
124 pub trait Sealed {}
125 }
126 pub trait State: sealed::Sealed {
128 type Issuer;
129 type Subject;
130 type Handle;
131 type CreatedAt;
132 type Uri;
133 type DisplayName;
134 }
135 pub struct Empty(());
137 impl sealed::Sealed for Empty {}
138 impl State for Empty {
139 type Issuer = Unset;
140 type Subject = Unset;
141 type Handle = Unset;
142 type CreatedAt = Unset;
143 type Uri = Unset;
144 type DisplayName = Unset;
145 }
146 pub struct SetIssuer<S: State = Empty>(PhantomData<fn() -> S>);
148 impl<S: State> sealed::Sealed for SetIssuer<S> {}
149 impl<S: State> State for SetIssuer<S> {
150 type Issuer = Set<members::issuer>;
151 type Subject = S::Subject;
152 type Handle = S::Handle;
153 type CreatedAt = S::CreatedAt;
154 type Uri = S::Uri;
155 type DisplayName = S::DisplayName;
156 }
157 pub struct SetSubject<S: State = Empty>(PhantomData<fn() -> S>);
159 impl<S: State> sealed::Sealed for SetSubject<S> {}
160 impl<S: State> State for SetSubject<S> {
161 type Issuer = S::Issuer;
162 type Subject = Set<members::subject>;
163 type Handle = S::Handle;
164 type CreatedAt = S::CreatedAt;
165 type Uri = S::Uri;
166 type DisplayName = S::DisplayName;
167 }
168 pub struct SetHandle<S: State = Empty>(PhantomData<fn() -> S>);
170 impl<S: State> sealed::Sealed for SetHandle<S> {}
171 impl<S: State> State for SetHandle<S> {
172 type Issuer = S::Issuer;
173 type Subject = S::Subject;
174 type Handle = Set<members::handle>;
175 type CreatedAt = S::CreatedAt;
176 type Uri = S::Uri;
177 type DisplayName = S::DisplayName;
178 }
179 pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
181 impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
182 impl<S: State> State for SetCreatedAt<S> {
183 type Issuer = S::Issuer;
184 type Subject = S::Subject;
185 type Handle = S::Handle;
186 type CreatedAt = Set<members::created_at>;
187 type Uri = S::Uri;
188 type DisplayName = S::DisplayName;
189 }
190 pub struct SetUri<S: State = Empty>(PhantomData<fn() -> S>);
192 impl<S: State> sealed::Sealed for SetUri<S> {}
193 impl<S: State> State for SetUri<S> {
194 type Issuer = S::Issuer;
195 type Subject = S::Subject;
196 type Handle = S::Handle;
197 type CreatedAt = S::CreatedAt;
198 type Uri = Set<members::uri>;
199 type DisplayName = S::DisplayName;
200 }
201 pub struct SetDisplayName<S: State = Empty>(PhantomData<fn() -> S>);
203 impl<S: State> sealed::Sealed for SetDisplayName<S> {}
204 impl<S: State> State for SetDisplayName<S> {
205 type Issuer = S::Issuer;
206 type Subject = S::Subject;
207 type Handle = S::Handle;
208 type CreatedAt = S::CreatedAt;
209 type Uri = S::Uri;
210 type DisplayName = Set<members::display_name>;
211 }
212 #[allow(non_camel_case_types)]
214 pub mod members {
215 pub struct issuer(());
217 pub struct subject(());
219 pub struct handle(());
221 pub struct created_at(());
223 pub struct uri(());
225 pub struct display_name(());
227 }
228}
229
230pub struct VerificationViewBuilder<'a, S: verification_view_state::State> {
232 _state: PhantomData<fn() -> S>,
233 _fields: (
234 Option<Datetime>,
235 Option<CowStr<'a>>,
236 Option<Handle<'a>>,
237 Option<Did<'a>>,
238 Option<Data<'a>>,
239 Option<VerificationViewIssuerRepo<'a>>,
240 Option<CowStr<'a>>,
241 Option<Datetime>,
242 Option<Did<'a>>,
243 Option<Did<'a>>,
244 Option<Data<'a>>,
245 Option<VerificationViewSubjectRepo<'a>>,
246 Option<AtUri<'a>>,
247 ),
248 _lifetime: PhantomData<&'a ()>,
249}
250
251impl<'a> VerificationView<'a> {
252 pub fn new() -> VerificationViewBuilder<'a, verification_view_state::Empty> {
254 VerificationViewBuilder::new()
255 }
256}
257
258impl<'a> VerificationViewBuilder<'a, verification_view_state::Empty> {
259 pub fn new() -> Self {
261 VerificationViewBuilder {
262 _state: PhantomData,
263 _fields: (
264 None,
265 None,
266 None,
267 None,
268 None,
269 None,
270 None,
271 None,
272 None,
273 None,
274 None,
275 None,
276 None,
277 ),
278 _lifetime: PhantomData,
279 }
280 }
281}
282
283impl<'a, S> VerificationViewBuilder<'a, S>
284where
285 S: verification_view_state::State,
286 S::CreatedAt: verification_view_state::IsUnset,
287{
288 pub fn created_at(
290 mut self,
291 value: impl Into<Datetime>,
292 ) -> VerificationViewBuilder<'a, verification_view_state::SetCreatedAt<S>> {
293 self._fields.0 = Option::Some(value.into());
294 VerificationViewBuilder {
295 _state: PhantomData,
296 _fields: self._fields,
297 _lifetime: PhantomData,
298 }
299 }
300}
301
302impl<'a, S> VerificationViewBuilder<'a, S>
303where
304 S: verification_view_state::State,
305 S::DisplayName: verification_view_state::IsUnset,
306{
307 pub fn display_name(
309 mut self,
310 value: impl Into<CowStr<'a>>,
311 ) -> VerificationViewBuilder<'a, verification_view_state::SetDisplayName<S>> {
312 self._fields.1 = Option::Some(value.into());
313 VerificationViewBuilder {
314 _state: PhantomData,
315 _fields: self._fields,
316 _lifetime: PhantomData,
317 }
318 }
319}
320
321impl<'a, S> VerificationViewBuilder<'a, S>
322where
323 S: verification_view_state::State,
324 S::Handle: verification_view_state::IsUnset,
325{
326 pub fn handle(
328 mut self,
329 value: impl Into<Handle<'a>>,
330 ) -> VerificationViewBuilder<'a, verification_view_state::SetHandle<S>> {
331 self._fields.2 = Option::Some(value.into());
332 VerificationViewBuilder {
333 _state: PhantomData,
334 _fields: self._fields,
335 _lifetime: PhantomData,
336 }
337 }
338}
339
340impl<'a, S> VerificationViewBuilder<'a, S>
341where
342 S: verification_view_state::State,
343 S::Issuer: verification_view_state::IsUnset,
344{
345 pub fn issuer(
347 mut self,
348 value: impl Into<Did<'a>>,
349 ) -> VerificationViewBuilder<'a, verification_view_state::SetIssuer<S>> {
350 self._fields.3 = Option::Some(value.into());
351 VerificationViewBuilder {
352 _state: PhantomData,
353 _fields: self._fields,
354 _lifetime: PhantomData,
355 }
356 }
357}
358
359impl<'a, S: verification_view_state::State> VerificationViewBuilder<'a, S> {
360 pub fn issuer_profile(mut self, value: impl Into<Option<Data<'a>>>) -> Self {
362 self._fields.4 = value.into();
363 self
364 }
365 pub fn maybe_issuer_profile(mut self, value: Option<Data<'a>>) -> Self {
367 self._fields.4 = value;
368 self
369 }
370}
371
372impl<'a, S: verification_view_state::State> VerificationViewBuilder<'a, S> {
373 pub fn issuer_repo(
375 mut self,
376 value: impl Into<Option<VerificationViewIssuerRepo<'a>>>,
377 ) -> Self {
378 self._fields.5 = value.into();
379 self
380 }
381 pub fn maybe_issuer_repo(
383 mut self,
384 value: Option<VerificationViewIssuerRepo<'a>>,
385 ) -> Self {
386 self._fields.5 = value;
387 self
388 }
389}
390
391impl<'a, S: verification_view_state::State> VerificationViewBuilder<'a, S> {
392 pub fn revoke_reason(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
394 self._fields.6 = value.into();
395 self
396 }
397 pub fn maybe_revoke_reason(mut self, value: Option<CowStr<'a>>) -> Self {
399 self._fields.6 = value;
400 self
401 }
402}
403
404impl<'a, S: verification_view_state::State> VerificationViewBuilder<'a, S> {
405 pub fn revoked_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
407 self._fields.7 = value.into();
408 self
409 }
410 pub fn maybe_revoked_at(mut self, value: Option<Datetime>) -> Self {
412 self._fields.7 = value;
413 self
414 }
415}
416
417impl<'a, S: verification_view_state::State> VerificationViewBuilder<'a, S> {
418 pub fn revoked_by(mut self, value: impl Into<Option<Did<'a>>>) -> Self {
420 self._fields.8 = value.into();
421 self
422 }
423 pub fn maybe_revoked_by(mut self, value: Option<Did<'a>>) -> Self {
425 self._fields.8 = value;
426 self
427 }
428}
429
430impl<'a, S> VerificationViewBuilder<'a, S>
431where
432 S: verification_view_state::State,
433 S::Subject: verification_view_state::IsUnset,
434{
435 pub fn subject(
437 mut self,
438 value: impl Into<Did<'a>>,
439 ) -> VerificationViewBuilder<'a, verification_view_state::SetSubject<S>> {
440 self._fields.9 = Option::Some(value.into());
441 VerificationViewBuilder {
442 _state: PhantomData,
443 _fields: self._fields,
444 _lifetime: PhantomData,
445 }
446 }
447}
448
449impl<'a, S: verification_view_state::State> VerificationViewBuilder<'a, S> {
450 pub fn subject_profile(mut self, value: impl Into<Option<Data<'a>>>) -> Self {
452 self._fields.10 = value.into();
453 self
454 }
455 pub fn maybe_subject_profile(mut self, value: Option<Data<'a>>) -> Self {
457 self._fields.10 = value;
458 self
459 }
460}
461
462impl<'a, S: verification_view_state::State> VerificationViewBuilder<'a, S> {
463 pub fn subject_repo(
465 mut self,
466 value: impl Into<Option<VerificationViewSubjectRepo<'a>>>,
467 ) -> Self {
468 self._fields.11 = value.into();
469 self
470 }
471 pub fn maybe_subject_repo(
473 mut self,
474 value: Option<VerificationViewSubjectRepo<'a>>,
475 ) -> Self {
476 self._fields.11 = value;
477 self
478 }
479}
480
481impl<'a, S> VerificationViewBuilder<'a, S>
482where
483 S: verification_view_state::State,
484 S::Uri: verification_view_state::IsUnset,
485{
486 pub fn uri(
488 mut self,
489 value: impl Into<AtUri<'a>>,
490 ) -> VerificationViewBuilder<'a, verification_view_state::SetUri<S>> {
491 self._fields.12 = Option::Some(value.into());
492 VerificationViewBuilder {
493 _state: PhantomData,
494 _fields: self._fields,
495 _lifetime: PhantomData,
496 }
497 }
498}
499
500impl<'a, S> VerificationViewBuilder<'a, S>
501where
502 S: verification_view_state::State,
503 S::Issuer: verification_view_state::IsSet,
504 S::Subject: verification_view_state::IsSet,
505 S::Handle: verification_view_state::IsSet,
506 S::CreatedAt: verification_view_state::IsSet,
507 S::Uri: verification_view_state::IsSet,
508 S::DisplayName: verification_view_state::IsSet,
509{
510 pub fn build(self) -> VerificationView<'a> {
512 VerificationView {
513 created_at: self._fields.0.unwrap(),
514 display_name: self._fields.1.unwrap(),
515 handle: self._fields.2.unwrap(),
516 issuer: self._fields.3.unwrap(),
517 issuer_profile: self._fields.4,
518 issuer_repo: self._fields.5,
519 revoke_reason: self._fields.6,
520 revoked_at: self._fields.7,
521 revoked_by: self._fields.8,
522 subject: self._fields.9.unwrap(),
523 subject_profile: self._fields.10,
524 subject_repo: self._fields.11,
525 uri: self._fields.12.unwrap(),
526 extra_data: Default::default(),
527 }
528 }
529 pub fn build_with_data(
531 self,
532 extra_data: BTreeMap<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
533 ) -> VerificationView<'a> {
534 VerificationView {
535 created_at: self._fields.0.unwrap(),
536 display_name: self._fields.1.unwrap(),
537 handle: self._fields.2.unwrap(),
538 issuer: self._fields.3.unwrap(),
539 issuer_profile: self._fields.4,
540 issuer_repo: self._fields.5,
541 revoke_reason: self._fields.6,
542 revoked_at: self._fields.7,
543 revoked_by: self._fields.8,
544 subject: self._fields.9.unwrap(),
545 subject_profile: self._fields.10,
546 subject_repo: self._fields.11,
547 uri: self._fields.12.unwrap(),
548 extra_data: Some(extra_data),
549 }
550 }
551}
552
553fn lexicon_doc_tools_ozone_verification_defs() -> LexiconDoc<'static> {
554 #[allow(unused_imports)]
555 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
556 use jacquard_lexicon::lexicon::*;
557 use alloc::collections::BTreeMap;
558 LexiconDoc {
559 lexicon: Lexicon::Lexicon1,
560 id: CowStr::new_static("tools.ozone.verification.defs"),
561 defs: {
562 let mut map = BTreeMap::new();
563 map.insert(
564 SmolStr::new_static("verificationView"),
565 LexUserType::Object(LexObject {
566 description: Some(
567 CowStr::new_static(
568 "Verification data for the associated subject.",
569 ),
570 ),
571 required: Some(
572 vec![
573 SmolStr::new_static("issuer"), SmolStr::new_static("uri"),
574 SmolStr::new_static("subject"),
575 SmolStr::new_static("handle"),
576 SmolStr::new_static("displayName"),
577 SmolStr::new_static("createdAt")
578 ],
579 ),
580 properties: {
581 #[allow(unused_mut)]
582 let mut map = BTreeMap::new();
583 map.insert(
584 SmolStr::new_static("createdAt"),
585 LexObjectProperty::String(LexString {
586 description: Some(
587 CowStr::new_static(
588 "Timestamp when the verification was created.",
589 ),
590 ),
591 format: Some(LexStringFormat::Datetime),
592 ..Default::default()
593 }),
594 );
595 map.insert(
596 SmolStr::new_static("displayName"),
597 LexObjectProperty::String(LexString {
598 description: Some(
599 CowStr::new_static(
600 "Display name of the subject the verification applies to at the moment of verifying, which might not be the same at the time of viewing. The verification is only valid if the current displayName matches the one at the time of verifying.",
601 ),
602 ),
603 ..Default::default()
604 }),
605 );
606 map.insert(
607 SmolStr::new_static("handle"),
608 LexObjectProperty::String(LexString {
609 description: Some(
610 CowStr::new_static(
611 "Handle of the subject the verification applies to at the moment of verifying, which might not be the same at the time of viewing. The verification is only valid if the current handle matches the one at the time of verifying.",
612 ),
613 ),
614 format: Some(LexStringFormat::Handle),
615 ..Default::default()
616 }),
617 );
618 map.insert(
619 SmolStr::new_static("issuer"),
620 LexObjectProperty::String(LexString {
621 description: Some(
622 CowStr::new_static("The user who issued this verification."),
623 ),
624 format: Some(LexStringFormat::Did),
625 ..Default::default()
626 }),
627 );
628 map.insert(
629 SmolStr::new_static("issuerProfile"),
630 LexObjectProperty::Union(LexRefUnion {
631 refs: vec![],
632 ..Default::default()
633 }),
634 );
635 map.insert(
636 SmolStr::new_static("issuerRepo"),
637 LexObjectProperty::Union(LexRefUnion {
638 refs: vec![
639 CowStr::new_static("tools.ozone.moderation.defs#repoViewDetail"),
640 CowStr::new_static("tools.ozone.moderation.defs#repoViewNotFound")
641 ],
642 ..Default::default()
643 }),
644 );
645 map.insert(
646 SmolStr::new_static("revokeReason"),
647 LexObjectProperty::String(LexString {
648 description: Some(
649 CowStr::new_static(
650 "Describes the reason for revocation, also indicating that the verification is no longer valid.",
651 ),
652 ),
653 ..Default::default()
654 }),
655 );
656 map.insert(
657 SmolStr::new_static("revokedAt"),
658 LexObjectProperty::String(LexString {
659 description: Some(
660 CowStr::new_static(
661 "Timestamp when the verification was revoked.",
662 ),
663 ),
664 format: Some(LexStringFormat::Datetime),
665 ..Default::default()
666 }),
667 );
668 map.insert(
669 SmolStr::new_static("revokedBy"),
670 LexObjectProperty::String(LexString {
671 description: Some(
672 CowStr::new_static(
673 "The user who revoked this verification.",
674 ),
675 ),
676 format: Some(LexStringFormat::Did),
677 ..Default::default()
678 }),
679 );
680 map.insert(
681 SmolStr::new_static("subject"),
682 LexObjectProperty::String(LexString {
683 description: Some(
684 CowStr::new_static("The subject of the verification."),
685 ),
686 format: Some(LexStringFormat::Did),
687 ..Default::default()
688 }),
689 );
690 map.insert(
691 SmolStr::new_static("subjectProfile"),
692 LexObjectProperty::Union(LexRefUnion {
693 refs: vec![],
694 ..Default::default()
695 }),
696 );
697 map.insert(
698 SmolStr::new_static("subjectRepo"),
699 LexObjectProperty::Union(LexRefUnion {
700 refs: vec![
701 CowStr::new_static("tools.ozone.moderation.defs#repoViewDetail"),
702 CowStr::new_static("tools.ozone.moderation.defs#repoViewNotFound")
703 ],
704 ..Default::default()
705 }),
706 );
707 map.insert(
708 SmolStr::new_static("uri"),
709 LexObjectProperty::String(LexString {
710 description: Some(
711 CowStr::new_static("The AT-URI of the verification record."),
712 ),
713 format: Some(LexStringFormat::AtUri),
714 ..Default::default()
715 }),
716 );
717 map
718 },
719 ..Default::default()
720 }),
721 );
722 map
723 },
724 ..Default::default()
725 }
726}