use chrono::NaiveDate;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use super::graph_properties::{GraphPropertyValue, ToNodeProperties};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum TimeApprovalStatus {
#[default]
Pending,
Approved,
Rejected,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TimeEntry {
pub entry_id: String,
pub employee_id: String,
pub date: NaiveDate,
pub hours_regular: f64,
pub hours_overtime: f64,
pub hours_pto: f64,
pub hours_sick: f64,
pub project_id: Option<String>,
pub cost_center: Option<String>,
pub description: Option<String>,
pub approval_status: TimeApprovalStatus,
pub approved_by: Option<String>,
pub submitted_at: Option<NaiveDate>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub employee_name: Option<String>,
#[serde(default)]
pub billable: bool,
}
impl ToNodeProperties for TimeEntry {
fn node_type_name(&self) -> &'static str {
"time_entry"
}
fn node_type_code(&self) -> u16 {
331
}
fn to_node_properties(&self) -> HashMap<String, GraphPropertyValue> {
let mut p = HashMap::new();
p.insert(
"entryId".into(),
GraphPropertyValue::String(self.entry_id.clone()),
);
p.insert(
"employeeId".into(),
GraphPropertyValue::String(self.employee_id.clone()),
);
if let Some(ref name) = self.employee_name {
p.insert(
"employeeName".into(),
GraphPropertyValue::String(name.clone()),
);
}
p.insert("date".into(), GraphPropertyValue::Date(self.date));
p.insert(
"hours".into(),
GraphPropertyValue::Float(self.hours_regular + self.hours_overtime),
);
p.insert(
"hoursRegular".into(),
GraphPropertyValue::Float(self.hours_regular),
);
p.insert(
"hoursOvertime".into(),
GraphPropertyValue::Float(self.hours_overtime),
);
p.insert("billable".into(), GraphPropertyValue::Bool(self.billable));
p.insert(
"status".into(),
GraphPropertyValue::String(format!("{:?}", self.approval_status)),
);
if let Some(ref proj) = self.project_id {
p.insert("projectId".into(), GraphPropertyValue::String(proj.clone()));
}
p
}
}