use crate::entities::contact::structure::Contact;
use super::structure::Manufacturer;
const MISSING_MANUFACTURER_ID: &str = "Manufacturer ID is required";
pub struct ManufacturerBuilder {
id: Option<String>,
name: Option<String>,
contact: Option<Contact>,
}
impl ManufacturerBuilder {
pub fn new() -> Self {
ManufacturerBuilder {
id: None,
name: None,
contact: None,
}
}
pub fn id(mut self, id: String) -> Self {
self.id = Some(id);
self
}
pub fn name(mut self, name: String) -> Self {
self.name = Some(name);
self
}
pub fn contact(mut self, contact: Contact) -> Self {
self.contact = Some(contact);
self
}
pub fn build(self) -> Result<Manufacturer, &'static str> {
Ok(Manufacturer {
id: self.id.ok_or(MISSING_MANUFACTURER_ID)?,
name: self.name,
contact: self.contact,
})
}
}
impl Default for ManufacturerBuilder {
fn default() -> Self {
Self::new()
}
}