use super::AddError;
use serde::{Deserialize, Serialize};
use strum::{Display, EnumIter, IntoEnumIterator};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Display, EnumIter)]
#[serde(rename_all = "lowercase")]
pub enum Tag {
Combat,
Compatibility,
#[strum(to_string = "{0}")]
Custom(String),
Dimensions,
Farming,
Gear,
Library,
Mobs,
Overworld,
Performance,
Progression,
Qol,
Storage,
Technology,
Visual,
Wildlife,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct TagInformation {
pub main: Option<Tag>,
pub others: Vec<Tag>,
}
pub(super) fn pick_main_tag() -> Result<Option<Tag>, AddError> {
let main_tag: Option<Tag> = {
let message = "Choose the main tag for this component:";
let options = Tag::iter()
.filter(|tag| !matches!(tag, Tag::Custom(_)))
.collect();
match inquire::Select::new(message, options)
.with_page_size(Tag::iter().count())
.with_help_message("Skip with [Escape] to provide a custom tag")
.prompt_skippable()?
{
tag @ Some(_) => tag,
None => {
let message = "Provide a custom tag for this component:";
inquire::Text::new(message)
.prompt_skippable()?
.map(|tag| tag.trim().to_lowercase())
.map(Tag::Custom)
}
}
};
Ok(main_tag)
}
pub(super) fn pick_secondary_tags(main_tag: Option<&Tag>) -> Result<Vec<Tag>, AddError> {
let other_tags: Vec<Tag> = {
let message = "Add some additional tags for this component?";
let options = Tag::iter()
.filter(|tag| !matches!(tag, Tag::Custom(_)) && main_tag != Some(tag))
.collect();
inquire::MultiSelect::new(message, options)
.with_page_size(Tag::iter().count())
.with_help_message("This step can be freely skipped.")
.prompt_skippable()?
.unwrap_or_default()
};
Ok(other_tags)
}