use printobserver_types::contract::Sample;
use printobserver_types::schemars::JsonSchema;
use printobserver_types::serde::{Deserialize, Serialize};
use crate::records::ids::CameraCheckId;
use crate::records::preflight::SheetId;
pub const CAMERA_CHECKED_KIND: &str = "camera_checked";
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", rename_all = "snake_case")]
#[schemars(crate = "printobserver_types::schemars")]
pub enum CameraCheckVerdict {
Aligned,
NotAligned,
Unavailable,
}
impl CameraCheckVerdict {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Aligned => "aligned",
Self::NotAligned => "not_aligned",
Self::Unavailable => "unavailable",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(crate = "printobserver_types::serde")]
pub struct CameraCheckStanding {
pub id: CameraCheckId,
pub sheet: SheetId,
pub verdict: CameraCheckVerdict,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(
crate = "printobserver_types::serde",
tag = "objection",
rename_all = "snake_case",
deny_unknown_fields
)]
#[schemars(crate = "printobserver_types::schemars")]
pub enum CameraCheckObjection {
Unknown,
NotAligned {
verdict: CameraCheckVerdict,
},
OtherSheet {
checked_on: SheetId,
declared: SheetId,
},
}
impl Sample for CameraCheckVerdict {
fn sample_full() -> Self {
Self::Aligned
}
fn sample_alternates() -> Vec<Self> {
vec![Self::NotAligned, Self::Unavailable]
}
}
impl Sample for CameraCheckObjection {
fn sample_full() -> Self {
Self::OtherSheet {
checked_on: sheet("textured-pei"),
declared: sheet("smooth-pei"),
}
}
fn sample_minimal() -> Self {
Self::Unknown
}
fn sample_alternates() -> Vec<Self> {
vec![Self::NotAligned {
verdict: CameraCheckVerdict::Unavailable,
}]
}
}
fn sheet(id: &str) -> SheetId {
SheetId::try_from(id.to_owned()).expect("a sheet named by something")
}