use crate::person::Person;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Resource {
Material(Material),
Personnel {
person: Person,
hourly_rate: Option<u16>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Material {
Consumable(Consumable),
NonConsumable(NonConsumable),
}
impl Default for Material {
fn default() -> Self {
Material::new("")
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Consumable {
name: String,
quantity: Option<u16>,
cost_per_unit: Option<u16>,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct NonConsumable {
name: String,
quantity: Option<u16>,
cost_per_unit: Option<u16>,
hourly_rate: Option<u16>,
}
impl From<NonConsumable> for Consumable {
fn from(value: NonConsumable) -> Self {
Consumable {
name: value.name,
quantity: value.quantity,
cost_per_unit: value.quantity,
}
}
}
impl From<Consumable> for NonConsumable {
fn from(value: Consumable) -> Self {
NonConsumable {
name: value.name,
quantity: value.quantity,
cost_per_unit: value.cost_per_unit,
hourly_rate: None,
}
}
}
impl Material {
pub fn new(name: impl Into<String>) -> Self {
Material::Consumable(Consumable::new(name))
}
pub fn name(&self) -> &str {
match self {
Material::Consumable(consumable) => &consumable.name,
Material::NonConsumable(non_consumable) => &non_consumable.name,
}
}
pub fn update_name(&mut self, name: impl Into<String>) {
match self {
Material::Consumable(consumable) => consumable.name = name.into(),
Material::NonConsumable(non_consumable) => non_consumable.name = name.into(),
}
}
pub fn quantity(&self) -> Option<u16> {
match self {
Material::Consumable(consumable) => consumable.quantity,
Material::NonConsumable(non_consumable) => non_consumable.quantity,
}
}
pub fn update_quantity(&mut self, quantity: u16) {
match self {
Material::Consumable(consumable) => consumable.quantity = Some(quantity),
Material::NonConsumable(non_consumable) => non_consumable.quantity = Some(quantity),
}
}
pub fn remove_quantity(&mut self) {
match self {
Material::Consumable(consumable) => consumable.quantity = None,
Material::NonConsumable(non_consumable) => non_consumable.quantity = None,
}
}
pub fn cost_per_unit(&self) -> Option<u16> {
match self {
Material::Consumable(consumable) => consumable.cost_per_unit,
Material::NonConsumable(non_consumable) => non_consumable.cost_per_unit,
}
}
pub fn update_cost_per_unit(&mut self, cost_per_unit: u16) {
match self {
Material::Consumable(consumable) => consumable.cost_per_unit = Some(cost_per_unit),
Material::NonConsumable(non_consumable) => {
non_consumable.cost_per_unit = Some(cost_per_unit)
}
}
}
pub fn remove_cost_per_unit(&mut self) {
match self {
Material::Consumable(consumable) => consumable.cost_per_unit = None,
Material::NonConsumable(non_consumable) => non_consumable.cost_per_unit = None,
}
}
}
impl Consumable {
pub fn new(name: impl Into<String>) -> Self {
Consumable {
name: name.into(),
quantity: None,
cost_per_unit: None,
}
}
}
impl NonConsumable {
pub fn new(name: impl Into<String>) -> Self {
NonConsumable {
name: name.into(),
quantity: None,
hourly_rate: None,
cost_per_unit: None,
}
}
pub fn hourly_rate(&self) -> Option<u16> {
self.hourly_rate
}
pub fn update_hourly_rate(&mut self, hourly_rate: u16) {
self.hourly_rate = Some(hourly_rate);
}
pub fn remove_hourly_rate(&mut self) {
self.hourly_rate = None;
}
}