use crate::{IdentError, Origin, Properties, product::ProductId};
#[derive(
Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, schemars::JsonSchema,
)]
#[serde(deny_unknown_fields)]
pub struct RequirementSchema {
#[serde(serialize_with = "crate::serialize_schema_version")]
pub schema_version: Option<String>,
pub requirements: Vec<Requirement>,
pub properties: Option<Properties>,
pub origin: Option<Origin>,
}
#[derive(
Debug,
Clone,
PartialEq,
Eq,
Hash,
serde::Serialize,
serde::Deserialize,
schemars::JsonSchema,
sqlx::Type,
)]
#[serde(transparent)]
#[sqlx(transparent)]
pub struct ReqId(String);
impl ReqId {
pub fn new(id: String) -> Result<Self, IdentError> {
Ok(Self(id))
}
}
impl std::ops::Deref for ReqId {
type Target = String;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl std::str::FromStr for ReqId {
type Err = IdentError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
ReqId::new(s.to_owned())
}
}
impl TryFrom<String> for ReqId {
type Error = IdentError;
fn try_from(value: String) -> Result<Self, Self::Error> {
ReqId::new(value)
}
}
impl std::fmt::Display for ReqId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(
Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, schemars::JsonSchema,
)]
#[serde(rename_all = "snake_case", deny_unknown_fields)]
pub struct Requirement {
pub id: ReqId,
pub parents: Option<Vec<RequirementPk>>,
pub title: String,
pub description: Option<String>,
pub origin: Origin,
#[serde(default)]
pub manual_verification: bool,
#[serde(default)]
pub deprecated: bool,
#[serde(default)]
pub exclude: bool,
#[serde(default)]
pub optional: bool,
pub properties: Option<Properties>,
}
#[derive(
Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, schemars::JsonSchema,
)]
#[serde(rename_all = "snake_case", deny_unknown_fields)]
pub struct RequirementPk {
pub id: ReqId,
pub product_id: Option<ProductId>,
}