dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts@v1.0.2/dtos/devicestatusupdate.go (about)

     1  package dtos
     2  
     3  import (
     4  	"time"
     5  
     6  	"dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/models"
     7  )
     8  
     9  type DeviceStatusUpdate struct {
    10  	DeviceName  string                `json:"deviceName"`            // The name or identifier of the device.
    11  	Status      *models.StatusKind    `json:"status,omitempty"`      // The current status of the device.
    12  	Origin      *int64                `json:"origin"`                // The origin or source of the status update.
    13  	LastUpdate  *int64                `json:"lastUpdate"`            // The timestamp of the last status update.
    14  	AlarmCount  *int64                `json:"alarmCount"`            // The number of alarms associated with the device.
    15  	MaxSeverity *models.AlarmSeverity `json:"maxSeverity,omitempty"` // The maximum severity level of the alarms for the device.
    16  	Silence     *models.SilenceKind   `json:"silence,omitempty"`     // The silent status of the device.
    17  }
    18  
    19  func NewDeviceStatusUpdate(deviceName string, options ...func(*DeviceStatusUpdate)) DeviceStatusUpdate {
    20  	t := time.Now().UnixMilli()
    21  	dsu := DeviceStatusUpdate{
    22  		DeviceName: deviceName,
    23  		Origin:     &t,
    24  	}
    25  	for _, o := range options {
    26  		o(&dsu)
    27  	}
    28  	return dsu
    29  }
    30  func WithStatus(status models.StatusKind) func(*DeviceStatusUpdate) {
    31  	return func(s *DeviceStatusUpdate) {
    32  		s.Status = &status
    33  	}
    34  }