use super::{
AccessCredentialObject, AccessRightsObject, AccessUserObject, CredentialDataInputObject,
};
use std::borrow::Cow;
use bacnet_types::enums::PropertyIdentifier as P;
use crate::property_metadata::{
PropertyConformance::{Optional, RequiredRead, RequiredWrite},
PropertyMetadata,
PropertyWriteCapability::{Always, ReadOnly, WhenOutOfService},
};
const ACCESS_CREDENTIAL_BASE: &[PropertyMetadata] = &[
PropertyMetadata::new(P::OBJECT_IDENTIFIER, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::OBJECT_NAME, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::DESCRIPTION, Optional, None, Always),
PropertyMetadata::new(P::OBJECT_TYPE, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::CREDENTIAL_STATUS, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::ASSIGNED_ACCESS_RIGHTS, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::AUTHENTICATION_FACTORS, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::STATUS_FLAGS, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::RELIABILITY, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::GLOBAL_IDENTIFIER, RequiredWrite, None, Always),
PropertyMetadata::new(P::REASON_FOR_DISABLE, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::ACTIVATION_TIME, RequiredRead, None, Always),
PropertyMetadata::new(P::EXPIRATION_TIME, RequiredRead, None, Always),
PropertyMetadata::new(P::CREDENTIAL_DISABLE, RequiredRead, None, Always),
PropertyMetadata::new(P::PROPERTY_LIST, RequiredRead, None, ReadOnly),
];
const ACCESS_USER_BASE: &[PropertyMetadata] = &[
PropertyMetadata::new(P::OBJECT_IDENTIFIER, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::OBJECT_NAME, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::DESCRIPTION, Optional, None, Always),
PropertyMetadata::new(P::OBJECT_TYPE, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::USER_TYPE, RequiredRead, None, Always),
PropertyMetadata::new(P::CREDENTIALS, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::STATUS_FLAGS, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::RELIABILITY, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::MEMBERS, Optional, None, ReadOnly),
PropertyMetadata::new(P::MEMBER_OF, Optional, None, ReadOnly),
PropertyMetadata::new(P::GLOBAL_IDENTIFIER, RequiredWrite, None, Always),
PropertyMetadata::new(P::PROPERTY_LIST, RequiredRead, None, ReadOnly),
];
const ACCESS_RIGHTS_BASE: &[PropertyMetadata] = &[
PropertyMetadata::new(P::OBJECT_IDENTIFIER, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::OBJECT_NAME, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::DESCRIPTION, Optional, None, Always),
PropertyMetadata::new(P::OBJECT_TYPE, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::GLOBAL_IDENTIFIER, RequiredWrite, None, Always),
PropertyMetadata::new(P::POSITIVE_ACCESS_RULES, RequiredRead, None, Always),
PropertyMetadata::new(P::NEGATIVE_ACCESS_RULES, RequiredRead, None, Always),
PropertyMetadata::new(P::STATUS_FLAGS, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::RELIABILITY, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::LOG_ENABLE, RequiredRead, None, Always),
PropertyMetadata::new(P::PROPERTY_LIST, RequiredRead, None, ReadOnly),
];
const CREDENTIAL_DATA_INPUT_BASE: &[PropertyMetadata] = &[
PropertyMetadata::new(P::OBJECT_IDENTIFIER, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::OBJECT_NAME, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::DESCRIPTION, Optional, None, Always),
PropertyMetadata::new(P::OBJECT_TYPE, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::PRESENT_VALUE, RequiredRead, None, WhenOutOfService),
PropertyMetadata::new(P::UPDATE_TIME, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::SUPPORTED_FORMATS, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::SUPPORTED_FORMAT_CLASSES, Optional, None, ReadOnly),
PropertyMetadata::new(P::STATUS_FLAGS, RequiredRead, None, ReadOnly),
PropertyMetadata::new(P::OUT_OF_SERVICE, RequiredRead, None, Always),
PropertyMetadata::new(P::RELIABILITY, RequiredRead, None, WhenOutOfService),
PropertyMetadata::new(P::PROPERTY_LIST, RequiredRead, None, ReadOnly),
];
pub(super) fn for_access_credential_object(
object: &AccessCredentialObject,
) -> Cow<'_, [PropertyMetadata]> {
if object.authorization_exemptions().is_none() {
return Cow::Borrowed(ACCESS_CREDENTIAL_BASE);
}
with_row_before_property_list(
ACCESS_CREDENTIAL_BASE,
PropertyMetadata::new(P::AUTHORIZATION_EXEMPTIONS, Optional, None, ReadOnly),
)
}
pub(super) fn for_access_user_object(_object: &AccessUserObject) -> Cow<'_, [PropertyMetadata]> {
Cow::Borrowed(ACCESS_USER_BASE)
}
pub(super) fn for_access_rights_object(object: &AccessRightsObject) -> Cow<'_, [PropertyMetadata]> {
if object.accompaniment().is_none() {
return Cow::Borrowed(ACCESS_RIGHTS_BASE);
}
with_row_before_property_list(
ACCESS_RIGHTS_BASE,
PropertyMetadata::new(P::ACCOMPANIMENT, Optional, None, Always),
)
}
fn with_row_before_property_list(
base: &[PropertyMetadata],
row: PropertyMetadata,
) -> Cow<'static, [PropertyMetadata]> {
let mut rows = base.to_vec();
let before_property_list = rows
.iter()
.position(|row| row.property_identifier == P::PROPERTY_LIST)
.expect("Property_List row");
rows.insert(before_property_list, row);
Cow::Owned(rows)
}
pub(super) fn for_credential_data_input_object(
_object: &CredentialDataInputObject,
) -> Cow<'_, [PropertyMetadata]> {
Cow::Borrowed(CREDENTIAL_DATA_INPUT_BASE)
}
#[cfg(test)]
#[path = "metadata_identity_tests.rs"]
mod tests;