use std::time::SystemTime;
use async_trait::async_trait;
use crate::CoolError;
use crate::idempotency_record::ReservationOutcome;
pub const MAX_BODY_BYTES: usize = 2 * 1024 * 1024;
#[async_trait]
pub trait IdempotencyStore: Send + Sync + 'static {
async fn reserve_or_fetch(
&self,
principal: &str,
key: &str,
request_hash: [u8; 32],
expires_at: SystemTime,
) -> Result<ReservationOutcome, CoolError>;
async fn complete(
&self,
principal: &str,
key: &str,
token: uuid::Uuid,
status: u16,
headers: &[u8],
body: &[u8],
) -> Result<(), CoolError>;
async fn release(&self, principal: &str, key: &str, token: uuid::Uuid)
-> Result<(), CoolError>;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn max_body_bytes_is_2_megabytes() {
assert_eq!(MAX_BODY_BYTES, 2 * 1024 * 1024);
}
}