use chrono::NaiveDate;
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use super::super::graph_properties::{GraphPropertyValue, ToNodeProperties};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum RfxType {
Rfi,
#[default]
Rfp,
Rfq,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum RfxStatus {
#[default]
Draft,
Published,
Closed,
Awarded,
Cancelled,
NoAward,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum ScoringMethod {
LowestPrice,
#[default]
BestValue,
QualityBased,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RfxEvaluationCriterion {
pub name: String,
pub weight: f64,
pub description: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RfxLineItem {
pub item_number: u16,
pub description: String,
pub material_id: Option<String>,
pub quantity: Decimal,
pub uom: String,
pub target_price: Option<Decimal>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RfxEvent {
pub rfx_id: String,
pub rfx_type: RfxType,
pub company_code: String,
pub title: String,
pub description: String,
pub status: RfxStatus,
pub sourcing_project_id: String,
pub category_id: String,
pub scoring_method: ScoringMethod,
pub criteria: Vec<RfxEvaluationCriterion>,
pub line_items: Vec<RfxLineItem>,
pub invited_vendors: Vec<String>,
pub publish_date: NaiveDate,
pub response_deadline: NaiveDate,
pub bid_count: u32,
pub owner_id: String,
pub awarded_vendor_id: Option<String>,
pub awarded_bid_id: Option<String>,
}
impl ToNodeProperties for RfxEvent {
fn node_type_name(&self) -> &'static str {
"rfx_event"
}
fn node_type_code(&self) -> u16 {
321
}
fn to_node_properties(&self) -> HashMap<String, GraphPropertyValue> {
let mut p = HashMap::new();
p.insert(
"rfxId".into(),
GraphPropertyValue::String(self.rfx_id.clone()),
);
p.insert(
"rfxType".into(),
GraphPropertyValue::String(format!("{:?}", self.rfx_type)),
);
p.insert(
"entityCode".into(),
GraphPropertyValue::String(self.company_code.clone()),
);
p.insert(
"title".into(),
GraphPropertyValue::String(self.title.clone()),
);
p.insert(
"status".into(),
GraphPropertyValue::String(format!("{:?}", self.status)),
);
p.insert(
"scoringMethod".into(),
GraphPropertyValue::String(format!("{:?}", self.scoring_method)),
);
p.insert(
"publishDate".into(),
GraphPropertyValue::Date(self.publish_date),
);
p.insert(
"responseDeadline".into(),
GraphPropertyValue::Date(self.response_deadline),
);
p.insert(
"bidCount".into(),
GraphPropertyValue::Int(self.bid_count as i64),
);
p.insert(
"invitedVendorCount".into(),
GraphPropertyValue::Int(self.invited_vendors.len() as i64),
);
p.insert(
"isAwarded".into(),
GraphPropertyValue::Bool(matches!(self.status, RfxStatus::Awarded)),
);
p
}
}