//! Sets of extensions for use with [Parameter](crate::parameters::Parameters)'s `-E` flag.
use clap::Clap;

#[derive(Clap, PartialEq, Debug)]
pub enum ExtensionSet {
	/// Extensions used for image file formats, such as `png`, `jpeg`, `webp`, etc.
	Images,
	/// Extensions used for audio file formats, such as `mp3`, `ogg`, `flac`, etc.
	Audio,
	/// Extensions used for video file formats, such as `mkv`, `mp4`, `mov`, etc.
	Videos,
	/// Extensions used for media file formats. This acts as a combination of the [Images](ExtensionSet::Images),
	/// [Audio](ExtensionSet::Audio) and [Videos](ExtensionSet::Videos) variants.
	Media,
	/// Extensions used for document file formats, such as `pdf`, `odt`, `docx`, etc.
	Documents,
	/// Extensions used for archive file formats, such as `zip`, `zst`, `gz`, etc.
	Archives,
}

impl ExtensionSet {
	/// The list of known extensions for this ExtensionSet.
	pub fn extensions(&self) -> Vec<&str> {
		match self {
			Self::Images => mime_guess::get_mime_extensions_str("image/*").unwrap().to_vec(),
			Self::Audio => mime_guess::get_mime_extensions_str("audio/*").unwrap().to_vec(),
			Self::Videos => mime_guess::get_mime_extensions_str("video/*").unwrap().to_vec(),
			Self::Media => [
				Self::Images.extensions(),
				Self::Audio.extensions(),
				Self::Videos.extensions(),
			]
			.concat(),
			Self::Documents => vec![
				"pdf", "doc", "docx", "ppt", "pptx", "xls", "xlsx", "csv", "tsv", "odt", "ods", "odp", "oda", "rtf", "ps",
			],
			// many compressed file types follow the name scheme "application/x.+compressed.*" - maybe this can be used
			// somehow to extract extensions for compressed files from mime_guess?
			Self::Archives => vec!["zip", "tar", "gz", "zst", "xz", "rar", "7z", "bz", "bz2"],
		}
	}
}
