use crate::wire::OperationCode;
use serde::{Deserialize, Serialize, Serializer};
use super::{EmptyResponse, Operation};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum FiscalReportKind {
X = 1,
Z = 2,
}
impl Serialize for FiscalReportKind {
fn serialize<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
ser.serialize_u8(*self as u8)
}
}
impl<'de> Deserialize<'de> for FiscalReportKind {
fn deserialize<D: serde::Deserializer<'de>>(de: D) -> Result<Self, D::Error> {
let code = u8::deserialize(de)?;
Ok(match code {
1 => Self::X,
2 => Self::Z,
other => {
return Err(serde::de::Error::custom(format!(
"unknown fiscal report kind code {other} (expected 1 or 2)"
)));
}
})
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub enum ReportFilter {
#[serde(rename = "deptId")]
Department(u32),
#[serde(rename = "cashierId")]
Cashier(u32),
#[serde(rename = "transactionTypeId")]
TransactionType(u32),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct FiscalReportRequest {
#[serde(rename = "reportType")]
#[cfg_attr(feature = "schema", schemars(with = "u8"))]
pub kind: FiscalReportKind,
#[serde(flatten)]
pub filter: Option<ReportFilter>,
#[serde(rename = "startDate")]
pub start_date: i64,
#[serde(rename = "endDate")]
pub end_date: i64,
}
impl Operation for FiscalReportRequest {
const CODE: OperationCode = OperationCode::PrintFiscalReport;
type Response = EmptyResponse;
}