use crate::wire::OperationCode;
use serde::{Deserialize, Serialize, Serializer};
use super::{EmptyResponse, Operation};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum TextAlign {
Left = 1,
Centered = 2,
Right = 3,
}
impl Serialize for TextAlign {
fn serialize<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
ser.serialize_u8(*self as u8)
}
}
impl<'de> Deserialize<'de> for TextAlign {
fn deserialize<D: serde::Deserializer<'de>>(de: D) -> Result<Self, D::Error> {
let code = u8::deserialize(de)?;
Ok(match code {
1 => Self::Left,
2 => Self::Centered,
3 => Self::Right,
other => {
return Err(serde::de::Error::custom(format!(
"unknown text alignment {other} (expected 1, 2, or 3)"
)));
}
})
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct TextLine {
#[cfg_attr(feature = "schema", schemars(with = "u8"))]
pub align: TextAlign,
pub bold: bool,
pub fsize: u8,
pub text: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct SetupHeaderFooterRequest {
#[serde(default)]
pub headers: Vec<TextLine>,
#[serde(default)]
pub footers: Vec<TextLine>,
}
impl Operation for SetupHeaderFooterRequest {
const CODE: OperationCode = OperationCode::SetupHeaderFooter;
type Response = EmptyResponse;
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct SetupHeaderLogoRequest {
#[serde(rename = "headerLogo")]
pub header_logo: String,
}
impl Operation for SetupHeaderLogoRequest {
const CODE: OperationCode = OperationCode::SetupHeaderLogo;
type Response = EmptyResponse;
}