made_core/ports/
host_delivery_query.rs1use crate::value_objects::{CeremonyId, HostDeliveryId, HostDeliveryRecord, HostDeliveryStateKind};
2
3use super::{HostDeliveryPageLimit, HostDeliveryTargetFilter};
4
5#[derive(Debug, Clone, Default, PartialEq, Eq)]
7pub struct HostDeliveryQuery {
8 ceremony_id: Option<CeremonyId>,
9 state: Option<HostDeliveryStateKind>,
10 target: HostDeliveryTargetFilter,
11 limit: HostDeliveryPageLimit,
12 cursor: Option<HostDeliveryId>,
13}
14
15impl HostDeliveryQuery {
16 #[must_use]
17 pub fn new() -> Self {
18 Self::default()
19 }
20
21 #[must_use]
22 pub fn in_ceremony(mut self, ceremony_id: CeremonyId) -> Self {
23 self.ceremony_id = Some(ceremony_id);
24 self
25 }
26
27 #[must_use]
28 pub fn in_state(mut self, state: HostDeliveryStateKind) -> Self {
29 self.state = Some(state);
30 self
31 }
32
33 #[must_use]
34 pub fn to(mut self, target: HostDeliveryTargetFilter) -> Self {
35 self.target = target;
36 self
37 }
38
39 #[must_use]
40 pub const fn of_size(mut self, limit: HostDeliveryPageLimit) -> Self {
41 self.limit = limit;
42 self
43 }
44
45 #[must_use]
47 pub fn after(mut self, cursor: HostDeliveryId) -> Self {
48 self.cursor = Some(cursor);
49 self
50 }
51
52 #[must_use]
53 pub const fn ceremony_id(&self) -> Option<&CeremonyId> {
54 self.ceremony_id.as_ref()
55 }
56
57 #[must_use]
58 pub const fn state(&self) -> Option<HostDeliveryStateKind> {
59 self.state
60 }
61
62 #[must_use]
63 pub const fn target(&self) -> &HostDeliveryTargetFilter {
64 &self.target
65 }
66
67 #[must_use]
68 pub const fn limit(&self) -> HostDeliveryPageLimit {
69 self.limit
70 }
71
72 #[must_use]
73 pub const fn cursor(&self) -> Option<&HostDeliveryId> {
74 self.cursor.as_ref()
75 }
76
77 #[must_use]
79 pub fn admits(&self, record: &HostDeliveryRecord) -> bool {
80 if let Some(ceremony_id) = &self.ceremony_id {
81 if record.item().ceremony_id() != ceremony_id {
82 return false;
83 }
84 }
85 if let Some(state) = self.state {
86 if record.state().kind() != state {
87 return false;
88 }
89 }
90 self.target.admits(record.target())
91 }
92}