tmflib 0.1.40

Interface library for processing TMF payloads
Documentation
// Copyright [2026] [Ryan Ruckley]

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

//     http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Performance Measurement object model for TMF628 Performance Management

use super::MOD_PATH;
use super::{MeasurementCollectionJobRef, PerformanceMeasurementRelationship};
use crate::{common::entity::Entity, HasDescription, HasId, IsAddressable, TimePeriod};
use serde::{Deserialize, Serialize};
use tmflib_derive::{HasDescription, HasId};

/// Path to this class
pub const CLASS_PATH: &str = "measurement";

/// Performance Measurement
#[derive(Debug, Clone, Serialize, HasDescription, Deserialize, Default, HasId)]
pub struct PerformanceMeasurement {
    ///Base entity schema for use in `TMForum` Open-APIs. Property.
    #[serde(flatten)]
    pub entity: Entity,
    /// Unique identifier of the performance measurement
    pub id: Option<String>,
    ///A URI to the performance measurement resource
    pub href: Option<String>,
    ///A free-text description of the performance measurement
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    ///Reference to a `MeasurementCollectionJob`
    #[serde(rename = "measurementCollectionJob")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub measurement_collection_job: Option<MeasurementCollectionJobRef>,
    ///related Performance measurements array
    #[serde(rename = "relatedMeasurement")]
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub related_measurement: Vec<PerformanceMeasurementRelationship>,
    ///The optional tag object attached to this entire measurement
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub tag: Option<serde_json::Value>,
    ///A period of time, either as a deadline (endDateTime only) a startDateTime only, or both
    #[serde(rename = "validFor")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub valid_for: Option<TimePeriod>,
}

impl IsAddressable for PerformanceMeasurement {
    fn get_objects() -> Vec<&'static str> {
        super::get_objects()
    }
}

impl std::fmt::Display for PerformanceMeasurement {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
        write!(f, "{}", serde_json::to_string(self).unwrap())
    }
}
impl std::ops::Deref for PerformanceMeasurement {
    type Target = Entity;
    fn deref(&self) -> &Self::Target {
        &self.entity
    }
}
impl std::ops::DerefMut for PerformanceMeasurement {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.entity
    }
}