use chrono::{DateTime, Utc};
#[derive(Debug, Clone, Copy)]
pub enum StartAt {
LiveOnly,
Sequence(u64),
Date(DateTime<Utc>),
}
#[derive(Debug, Clone)]
pub struct BatchParams {
pub topic: String,
pub start_at: StartAt,
pub limit: usize,
}
impl BatchParams {
pub fn new(topic: String, limit: usize) -> Self {
Self {
topic,
start_at: StartAt::LiveOnly,
limit,
}
}
pub fn with_sequence(mut self, sequence: u64) -> Self {
self.start_at = StartAt::Sequence(sequence);
self
}
pub fn with_date(mut self, date: DateTime<Utc>) -> Self {
self.start_at = StartAt::Date(date);
self
}
pub fn with_start_at(mut self, start_at: StartAt) -> Self {
self.start_at = start_at;
self
}
}
impl StartAt {
pub fn as_replay_cursor(self) -> (Option<u64>, Option<DateTime<Utc>>) {
match self {
StartAt::Sequence(seq) => (Some(seq), None),
StartAt::Date(date) => (None, Some(date)),
StartAt::LiveOnly => (None, None),
}
}
}