use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
#[non_exhaustive]
pub enum PathFieldCommand {
FileName,
Path,
PathAndFileName,
Unknown(String),
}
impl PathFieldCommand {
pub fn wire_command(&self) -> &str {
match self {
Self::FileName => "$F",
Self::Path => "$P",
Self::PathAndFileName => "$P$F",
Self::Unknown(s) => s.as_str(),
}
}
pub fn from_wire(cmd: &str) -> Self {
match cmd {
"$F" => Self::FileName,
"$P" => Self::Path,
"$P$F" => Self::PathAndFileName,
other => Self::Unknown(other.to_string()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
#[non_exhaustive]
pub enum RefTarget {
Name(String),
SystemId(u64),
Raw(String),
}
impl RefTarget {
pub fn as_display(&self) -> String {
match self {
Self::Name(s) => s.clone(),
Self::SystemId(id) => format!("#{id}"),
Self::Raw(s) => s.clone(),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
#[non_exhaustive]
pub enum InlinePageKind {
CurrentPage,
TotalPages,
Unknown,
}
impl InlinePageKind {
pub fn raw_flag(self) -> Option<u32> {
match self {
Self::CurrentPage => Some(0x00),
Self::TotalPages => Some(0x06),
Self::Unknown => None,
}
}
pub fn from_raw_flag(flag: u32) -> Self {
match flag {
0x00 => Self::CurrentPage,
0x06 => Self::TotalPages,
_ => Self::Unknown,
}
}
}