use std::time::Duration;
#[derive(Clone, Debug, PartialEq)]
pub struct CopyOptions {
sensitive: bool,
expires_after: Option<Duration>,
local_only: bool,
}
impl Default for CopyOptions {
fn default() -> Self {
Self::new()
}
}
impl CopyOptions {
#[must_use]
pub fn new() -> Self {
Self { sensitive: false, expires_after: None, local_only: false }
}
#[must_use]
pub fn sensitive() -> Self {
Self { sensitive: true, expires_after: Some(Duration::from_secs(120)), local_only: true }
}
#[must_use]
pub fn mark_sensitive(mut self, on: bool) -> Self {
self.sensitive = on;
self
}
#[must_use]
pub fn expires_after(mut self, d: Duration) -> Self {
self.expires_after = Some(d.max(Duration::from_secs(1)));
self
}
#[must_use]
pub fn never_expires(mut self) -> Self {
self.expires_after = None;
self
}
#[must_use]
pub fn local_only(mut self, on: bool) -> Self {
self.local_only = on;
self
}
pub(crate) fn to_input(&self, text: &str) -> String {
let expires_ms = self.expires_after.map(|d| u64::try_from(d.as_millis()).unwrap_or(u64::MAX));
serde_json::json!({
"text": text,
"sensitive": self.sensitive,
"expires_ms": expires_ms,
"local_only": self.local_only,
})
.to_string()
}
}