use ifc_model::{Entity, EntityId, Value};
use crate::error::CostError;
use crate::release::{AuthoredDateTime, ReadRelease};
use crate::SchemaVersion;
const ENTITY: &str = "IFCCOSTSCHEDULE";
#[derive(Debug, Clone, Copy)]
pub struct CostSchedule<'m> {
id: EntityId,
entity: &'m Entity,
release: ReadRelease,
}
impl<'m> CostSchedule<'m> {
pub fn new(
id: EntityId,
entity: &'m Entity,
release: SchemaVersion,
) -> Result<Self, CostError> {
Ok(Self::bound(id, entity, ReadRelease::of_version(release)?))
}
pub(crate) const fn bound(id: EntityId, entity: &'m Entity, release: ReadRelease) -> Self {
Self {
id,
entity,
release,
}
}
pub fn id(&self) -> EntityId {
self.id
}
pub fn release(&self) -> SchemaVersion {
self.release.version()
}
fn text(&self, attribute: &str) -> Option<&'m str> {
self.release.text(ENTITY, self.entity, attribute)
}
pub fn global_id(&self) -> Option<&'m str> {
self.text("GlobalId")
}
pub fn name(&self) -> Option<&'m str> {
self.text("Name")
}
pub fn identification(&self) -> Option<&'m str> {
match self.release.version() {
SchemaVersion::Ifc2x3 => self.text("ID"),
_ => self.text("Identification"),
}
}
pub fn status(&self) -> Option<&'m str> {
self.text("Status")
}
pub fn submitted_on(&self) -> Option<AuthoredDateTime<'m>> {
self.release.date_time(ENTITY, self.entity, "SubmittedOn")
}
pub fn update_date(&self) -> Option<AuthoredDateTime<'m>> {
self.release.date_time(ENTITY, self.entity, "UpdateDate")
}
pub fn predefined_type(&self) -> Option<&'m str> {
match self.release.value(ENTITY, self.entity, "PredefinedType")? {
Value::Enum(e) => Some(e),
_ => None,
}
}
}