#[serde_with::serde_as]
#[derive(Debug,serde::Deserialize)]
#[serde(default)]
#[serde(deny_unknown_fields)]
#[serde(rename_all="kebab-case")]
pub struct Config {
	#[serde_as(as="serde_with::FromInto<crate::SerdeBytes>")] pub target_free: u64,
	#[serde_as(as="serde_with::FromInto<crate::SerdeDuration>")] pub last_activity_min: std::time::Duration,
	#[serde_as(as="serde_with::FromInto<crate::SerdeDuration>")] pub seed_time_min: std::time::Duration,
	pub age_d_max_weight: f64,
	pub categories_allowed: std::collections::HashSet<String>,
	pub copies_weight: f64,
	pub last_activity_d_weight: f64,
	pub qbt_url: url::Url,
	pub rules: Vec<crate::Rule>,
	pub seeder_count_min: u64,
	pub seeder_count_weight: f64,
	pub size_weight: f64,
	pub state_allowed: std::collections::HashSet<crate::TorrentState>,
}

impl Default for Config {
	fn default() -> Self {
		Config {
			age_d_max_weight: 0.0,
			categories_allowed: Default::default(),
			copies_weight: 0.0,
			last_activity_d_weight: 0.0,
			last_activity_min: std::time::Duration::from_secs(7 * 24 * 3600),
			qbt_url: "http://localhost:8080".parse().unwrap(),
			rules: Vec::new(),
			seed_time_min: std::time::Duration::from_secs(14 * 24 * 3600),
			seeder_count_min: 3,
			seeder_count_weight: 0.0,
			size_weight: 0.0,
			state_allowed: [
				crate::TorrentState::Error,
				crate::TorrentState::MissingFiles,
				crate::TorrentState::StoppedDownloading,
				crate::TorrentState::StoppedUploading,
				crate::TorrentState::UploadingForced,
				crate::TorrentState::UploadingQueued,
				crate::TorrentState::UploadingStalled,
			].into(),
			target_free: 10_000_000_000,
		}
	}
}

