use crate::http_client::HttpClient;
use crate::record::from_system_time;
use http::Method;
use reduct_base::error::ReductError;
use std::sync::Arc;
pub struct RemoveRecordBuilder {
bucket: String,
entry: String,
timestamp: Option<u64>,
client: Arc<HttpClient>,
}
impl RemoveRecordBuilder {
pub(crate) fn new(bucket: String, entry: String, client: Arc<HttpClient>) -> Self {
Self {
bucket,
entry,
timestamp: None,
client,
}
}
pub fn timestamp_us(mut self, timestamp: u64) -> Self {
self.timestamp = Some(timestamp);
self
}
pub fn timestamp(mut self, timestamp: std::time::SystemTime) -> Self {
self.timestamp = Some(from_system_time(timestamp));
self
}
pub async fn send(self) -> Result<(), ReductError> {
let request = self.client.request(
Method::DELETE,
&format!(
"/b/{}/{}?ts={}",
self.bucket,
self.entry,
self.timestamp.expect("timestamp is required")
),
);
self.client.send_request(request).await?;
Ok(())
}
}