use std::ops::Deref;
use rho_tools::tool_card::ToolCard;
use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub(crate) enum ToolBodyWindow {
#[default]
Head,
Tail,
}
impl ToolBodyWindow {
fn is_head(&self) -> bool {
matches!(self, Self::Head)
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "kind", rename_all = "snake_case")]
pub(crate) enum ToolBodySyntax {
#[default]
Plain,
Code {
language: String,
#[serde(default, skip_serializing_if = "ToolBodyWindow::is_head")]
window: ToolBodyWindow,
},
}
impl ToolBodySyntax {
fn is_plain(&self) -> bool {
matches!(self, Self::Plain)
}
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub(crate) struct PresentedToolCard {
#[serde(flatten)]
pub(crate) card: ToolCard,
#[serde(default, skip_serializing_if = "ToolBodySyntax::is_plain")]
pub(crate) body_syntax: ToolBodySyntax,
}
impl From<ToolCard> for PresentedToolCard {
fn from(card: ToolCard) -> Self {
Self {
card,
body_syntax: ToolBodySyntax::Plain,
}
}
}
impl Deref for PresentedToolCard {
type Target = ToolCard;
fn deref(&self) -> &Self::Target {
&self.card
}
}
#[cfg(test)]
#[path = "interactive_presenter_tool_card_tests.rs"]
mod tests;