use crate::prelude::*;
use caesura_macros::Options;
use serde::{Deserialize, Serialize};
use std::time::Duration;
#[derive(Options, Clone, Debug, Deserialize, Serialize)]
#[allow(clippy::struct_excessive_bools)]
pub struct BatchOptions {
#[arg(long)]
pub spectrogram: bool,
#[arg(long)]
pub transcode: bool,
#[arg(long)]
pub retry_transcode: bool,
#[arg(long)]
pub upload: bool,
#[arg(long)]
#[options(default = 3)]
pub limit: usize,
#[arg(long)]
pub no_limit: bool,
#[arg(long)]
pub wait_before_upload: Option<String>,
}
impl BatchOptions {
#[must_use]
pub fn get_wait_before_upload(&self) -> Option<Duration> {
let wait_before_upload = self.wait_before_upload.clone()?;
humantime::parse_duration(wait_before_upload.as_str()).ok()
}
#[must_use]
pub fn get_limit(&self) -> Option<usize> {
if self.no_limit {
None
} else {
Some(self.limit)
}
}
}
impl OptionsContract for BatchOptions {
type Partial = BatchOptionsPartial;
fn validate(&self, errors: &mut Vec<OptionRule>) {
if let Some(wait_before_upload) = &self.wait_before_upload
&& humantime::parse_duration(wait_before_upload.as_str()).is_err()
{
errors.push(OptionRule::DurationInvalid(
"Wait Before Upload".to_owned(),
wait_before_upload.clone(),
));
}
if self.upload && !self.transcode {
errors.push(OptionRule::Dependent(
"Upload".to_owned(),
"Transcode".to_owned(),
));
}
}
}