use crate::error::DevbrainError;
use serde::{Deserialize, Serialize};
use std::str::FromStr;
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct Entry {
pub entry_type: EntryType,
pub content: String,
pub project: String,
pub timestamp: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum EntryType {
Log,
Command,
Error,
}
impl EntryType {
pub fn as_str(&self) -> &'static str {
match self {
Self::Log => "log",
Self::Command => "command",
Self::Error => "error",
}
}
}
impl FromStr for EntryType {
type Err = DevbrainError;
fn from_str(value: &str) -> Result<Self, Self::Err> {
match value {
"log" => Ok(Self::Log),
"command" => Ok(Self::Command),
"error" => Ok(Self::Error),
_ => Err(DevbrainError::InvalidEntryType(
"Use: log, command, error".to_string(),
)),
}
}
}