use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct OutputConfig {
pub include_timestamps: bool,
pub include_ids: bool,
pub include_replies: bool,
pub include_edited: bool,
}
impl OutputConfig {
pub fn new() -> Self {
Self::default()
}
pub fn all() -> Self {
Self {
include_timestamps: true,
include_ids: true,
include_replies: true,
include_edited: true,
}
}
#[must_use]
pub fn with_timestamps(mut self) -> Self {
self.include_timestamps = true;
self
}
#[must_use]
pub fn with_ids(mut self) -> Self {
self.include_ids = true;
self
}
#[must_use]
pub fn with_replies(mut self) -> Self {
self.include_replies = true;
self
}
#[must_use]
pub fn with_edited(mut self) -> Self {
self.include_edited = true;
self
}
pub fn has_any(&self) -> bool {
self.include_timestamps || self.include_ids || self.include_replies || self.include_edited
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_output_config_builder() {
let config = OutputConfig::new().with_timestamps().with_ids();
assert!(config.include_timestamps);
assert!(config.include_ids);
assert!(!config.include_replies);
assert!(!config.include_edited);
}
#[test]
fn test_output_config_all() {
let config = OutputConfig::all();
assert!(config.include_timestamps);
assert!(config.include_ids);
assert!(config.include_replies);
assert!(config.include_edited);
}
#[test]
fn test_output_config_has_any() {
assert!(!OutputConfig::new().has_any());
assert!(OutputConfig::new().with_timestamps().has_any());
}
}