use crate::{Position, ReadDirection, StreamPosition};
use eventstore_macros::{options, streaming};
options! {
#[derive(Clone)]
#[streaming]
pub struct ReadAllOptions {
pub(crate) direction: ReadDirection,
pub(crate) position: StreamPosition<Position>,
pub(crate) resolve_link_tos: bool,
pub(crate) max_count: usize,
}
}
impl Default for ReadAllOptions {
fn default() -> Self {
Self {
direction: ReadDirection::Forward,
position: StreamPosition::Start,
resolve_link_tos: false,
common_operation_options: Default::default(),
max_count: usize::MAX,
}
}
}
impl ReadAllOptions {
pub fn forwards(self) -> Self {
Self {
direction: ReadDirection::Forward,
..self
}
}
pub fn backwards(self) -> Self {
Self {
direction: ReadDirection::Backward,
..self
}
}
pub fn position(self, position: StreamPosition<Position>) -> Self {
match position {
StreamPosition::Start => Self {
position,
direction: ReadDirection::Forward,
..self
},
StreamPosition::End => Self {
position,
direction: ReadDirection::Backward,
..self
},
StreamPosition::Position(_) => Self { position, ..self },
}
}
pub fn resolve_link_tos(self) -> Self {
Self {
resolve_link_tos: true,
..self
}
}
pub fn max_count(self, max_count: usize) -> Self {
Self { max_count, ..self }
}
}