use serde::{Deserialize, Serialize};
use uuid::Uuid;
use crate::common::note::Note;
#[cfg(all(feature = "tmf620", feature = "build-V4"))]
use crate::tmf620::product_offering::ProductOfferingRef;
#[cfg(all(feature = "tmf620", feature = "build-V5"))]
use crate::tmf620::product_offering_v5::ProductOfferingRef;
use super::product_qualification::TaskStateType;
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub enum ProductActionType {
Add,
Modify,
Delete,
#[default]
NoChange,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ProductOfferingQualificationItem {
pub action: ProductActionType,
pub id: Option<String>,
pub note: Vec<Note>,
pub state: TaskStateType,
pub product_offering: Option<ProductOfferingRef>,
}
impl ProductOfferingQualificationItem {
pub fn new() -> ProductOfferingQualificationItem {
let id = Uuid::new_v4().simple().to_string();
ProductOfferingQualificationItem {
id: Some(id),
..Default::default()
}
}
}
#[cfg(test)]
mod test {
use super::{ProductActionType, ProductOfferingQualificationItem};
use crate::tmf679::product_qualification::TaskStateType;
const ACTIONTYPE: &str = "\"NoChange\"";
const POQI_JSON: &str = "{
\"action\" : \"NoChange\",
\"note\" : [],
\"state\" : \"InProgress\"
}";
#[test]
fn test_actiontype_deserialize() {
let actiontype: ProductActionType = serde_json::from_str(ACTIONTYPE).unwrap();
assert_eq!(actiontype, ProductActionType::NoChange);
}
#[test]
fn test_poqi_deserialize() {
let poqi: ProductOfferingQualificationItem = serde_json::from_str(POQI_JSON).unwrap();
assert_eq!(poqi.action, ProductActionType::NoChange);
assert_eq!(poqi.state, TaskStateType::InProgress);
}
#[test]
fn test_poqi_new() {
let poqi = ProductOfferingQualificationItem::new();
assert_eq!(poqi.id.is_some(), true);
}
}