use std::panic::RefUnwindSafe;
use yaserde::{YaDeserialize, YaSerialize};
use crate::packages::{
identification::{ResponseRequired, ResponseStatus},
objects::EventStatus,
primitives::{HexBinary160, String32, Uint32},
types::{
DateTimeInterval, MRIDType, OneHourRangeType, SubscribableType, TimeType, VersionType,
},
};
#[cfg(feature = "metering_mirror")]
use crate::packages::{
primitives::Int48,
types::{ConsumptionBlockType, QualityFlags, RoleFlagsType, ServiceKind, TOUType},
};
#[cfg(feature = "billing")]
use crate::packages::links::{BillingReadingSetListLink, ReadingTypeLink};
#[cfg(feature = "fsa")]
use crate::packages::links::{
CustomerAccountListLink, DERProgramListLink, DemandResponseProgramListLink, FileListLink,
MessagingProgramListLink, PrepaymentListLink, ResponseSetListLink, TariffProfileListLink,
TimeLink, UsagePointListLink,
};
#[cfg(feature = "edev")]
use crate::packages::{
links::{
ConfigurationLink, DERListLink, DeviceInformationLink, DeviceStatusLink, FileStatusLink,
IPInterfaceListLink, LoadShedAvailabilityListLink, LogEventListLink, PowerStatusLink,
},
types::{DeviceCategoryType, SFDIType},
};
pub trait SEType:
YaSerialize + YaDeserialize + Validate + RefUnwindSafe + Send + Sync + 'static
{
}
impl<T> SEType for T where
T: YaSerialize + YaDeserialize + Validate + RefUnwindSafe + Send + Sync + 'static
{
}
pub trait SEResource: SEType {
fn href(&self) -> Option<&str>;
}
pub trait SEResponse: SEResource {
fn created_date_time(&self) -> Option<TimeType>;
fn end_device_lfdi(&self) -> &HexBinary160;
fn status(&self) -> Option<ResponseStatus>;
fn subject(&self) -> &MRIDType;
}
pub trait SEIdentifiedObject: SEResource {
fn mrid(&self) -> &MRIDType;
fn description(&self) -> Option<&String32>;
fn version(&self) -> Option<VersionType>;
}
pub trait SERespondableResource: SEResource {
fn reply_to(&self) -> Option<&str>;
fn response_required(&self) -> Option<ResponseRequired>;
}
#[cfg(feature = "pubsub")]
pub trait SESubscriptionBase: SEResource {
fn subscribed_resource(&self) -> &str;
}
pub trait SESubscribableResource: SEResource {
fn subscribable(&self) -> Option<SubscribableType>;
}
pub trait SERespondableIdentifiedObject: SERespondableResource + SEIdentifiedObject {}
pub trait SERespondableSubscribableIdentifiedObject:
SERespondableResource + SESubscribableResource + SEIdentifiedObject
{
}
pub trait SESubscribableIdentifiedObject: SESubscribableResource + SEIdentifiedObject {}
pub trait SEEvent: SERespondableSubscribableIdentifiedObject {
fn creation_time(&self) -> TimeType;
fn event_status(&self) -> &EventStatus;
fn interval(&self) -> &DateTimeInterval;
}
pub trait SERandomizableEvent: SEEvent {
fn randomize_duration(&self) -> Option<OneHourRangeType>;
fn randomize_start(&self) -> Option<OneHourRangeType>;
}
pub trait SEList: SEResource {
type Inner: Ord;
fn all(&self) -> Uint32;
fn all_mut(&mut self) -> &mut Uint32;
fn results(&self) -> Uint32;
fn results_mut(&mut self) -> &mut Uint32;
fn list_as_slice(&self) -> &[Self::Inner];
fn list_mut(&mut self) -> &mut Vec<Self::Inner>;
fn add(&mut self, item: Self::Inner) {
self.list_mut().push(item);
self.list_mut().sort();
*self.all_mut() = Uint32(self.all().get() + 1);
}
fn remove(&mut self, idx: usize) -> Self::Inner {
*self.all_mut() = Uint32(self.all().get() - 1);
self.list_mut().remove(idx)
}
}
pub trait SESubscribableList: SESubscribableResource + SEList {}
#[cfg(feature = "fsa")]
pub trait SEFunctionSetAssignmentsBase: SEResource {
fn customer_account_list_link(&self) -> Option<&CustomerAccountListLink>;
fn demand_response_program_list_link(&self) -> Option<&DemandResponseProgramListLink>;
fn der_program_list_link(&self) -> Option<&DERProgramListLink>;
fn file_list_link(&self) -> Option<&FileListLink>;
fn messaging_program_list_link(&self) -> Option<&MessagingProgramListLink>;
fn prepayment_list_link(&self) -> Option<&PrepaymentListLink>;
fn response_set_list_link(&self) -> Option<&ResponseSetListLink>;
fn tariff_profile_list_link(&self) -> Option<&TariffProfileListLink>;
fn time_link(&self) -> Option<&TimeLink>;
fn usage_point_list_link(&self) -> Option<&UsagePointListLink>;
}
#[cfg(feature = "edev")]
pub trait SEAbstractDevice: SESubscribableResource {
fn configuration_link(&self) -> Option<&ConfigurationLink>;
fn der_list_link(&self) -> Option<&DERListLink>;
fn device_category(&self) -> Option<DeviceCategoryType>;
fn device_information_link(&self) -> Option<&DeviceInformationLink>;
fn device_status_link(&self) -> Option<&DeviceStatusLink>;
fn file_status_link(&self) -> Option<&FileStatusLink>;
fn ip_interface_list_link(&self) -> Option<&IPInterfaceListLink>;
fn lfdi(&self) -> Option<&HexBinary160>;
fn load_shed_availability_list_link(&self) -> Option<&LoadShedAvailabilityListLink>;
fn log_event_list_link(&self) -> Option<&LogEventListLink>;
fn power_status_link(&self) -> Option<&PowerStatusLink>;
fn sfdi(&self) -> SFDIType;
}
#[cfg(feature = "metering_mirror")]
pub trait SEMeterReadingBase: SEIdentifiedObject {
}
#[cfg(feature = "metering_mirror")]
pub trait SEReadingBase: SEResource {
fn consumption_block(&self) -> Option<ConsumptionBlockType>;
fn quality_flags(&self) -> Option<QualityFlags>;
fn time_period(&self) -> Option<&DateTimeInterval>;
fn tou_tier(&self) -> Option<TOUType>;
fn value(&self) -> Option<Int48>;
}
#[cfg(feature = "metering_mirror")]
pub trait SEReadingSetBase: SEIdentifiedObject {
fn time_period(&self) -> &DateTimeInterval;
}
#[cfg(feature = "metering_mirror")]
pub trait SEUsagePointBase: SEIdentifiedObject {
fn role_flags(&self) -> RoleFlagsType;
fn service_category_kind(&self) -> ServiceKind;
}
#[cfg(feature = "billing")]
pub trait SEBillingMeterReadingBase: SEMeterReadingBase {
fn billing_reading_set_list_link(&self) -> Option<&BillingReadingSetListLink>;
fn reading_type_link(&self) -> Option<&ReadingTypeLink>;
}
pub trait Validate {
fn validate(&self) -> Result<(), String> {
Ok(())
}
}