devbrain 0.2.0

Local-first CLI to capture, search, and recall developer workflow (commands, errors, and fixes)
use crate::error::DevbrainError;
use serde::{Deserialize, Serialize};
use std::str::FromStr;

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
pub struct Entry {
    pub entry_type: EntryType,
    pub content: String,
    pub project: String,
    pub timestamp: String,
    #[serde(default)]
    pub session_id: Option<String>,
    #[serde(default)]
    pub success: Option<bool>,
    #[serde(default)]
    pub tags: Vec<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
#[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(),
            )),
        }
    }
}