use std::fmt::{Display, Write};
use serde::{Deserialize, Serialize};
use strum::EnumString;
use crate::action::Action;
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct Vessel {
pub article: Option<Article>,
pub note: Option<String>,
pub program: Option<Vec<Action>>,
}
impl Vessel {
pub fn new(
article: Option<Article>,
note: Option<String>,
program: Option<Vec<Action>>,
) -> Self {
Self {
article,
note,
program,
}
}
pub fn with_article(article: Option<Article>) -> Self {
Self {
article,
note: None,
program: None,
}
}
}
impl Default for Vessel {
fn default() -> Self {
Self {
article: Some(Article::A),
note: None,
program: None,
}
}
}
#[derive(
Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, EnumString,
)]
#[strum(ascii_case_insensitive)]
pub enum Article {
A,
An,
The,
}
impl Display for Article {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Article::A => f.write_str("a"),
Article::An => f.write_str("an"),
Article::The => f.write_str("the"),
}
}
}
pub fn vessel_text(name: &str, article: &Option<Article>) -> String {
let mut out = String::new();
if let Some(article) = article {
out.write_str(&format!("{article} ")).unwrap();
}
out.write_str(name).unwrap();
out
}