Option Strict On
Option Explicit On

Imports System
Imports System.Globalization

Namespace Nexamas.UI.DiagnosticsDashboard

    ''' <summary>
    ''' Immutable metric row for the read-only diagnostics dashboard foundation.
    ''' </summary>
    Friend NotInheritable Class MASDiagnosticsDashboardMetric

        Friend Sub New(kind As MASDiagnosticsDashboardMetricKind,
                       title As String,
                       value As Double,
                       unitName As String,
                       sourceName As String,
                       isAvailable As Boolean,
                       isWarning As Boolean,
                       description As String)
            Me.Kind = kind
            Me.Title = If(title, String.Empty)
            Me.Value = Math.Max(0.0R, value)
            Me.UnitName = If(unitName, String.Empty)
            Me.SourceName = If(sourceName, String.Empty)
            Me.IsAvailable = isAvailable
            Me.IsWarning = isWarning
            Me.Description = If(description, String.Empty)
        End Sub

        Friend ReadOnly Property Kind As MASDiagnosticsDashboardMetricKind
        Friend ReadOnly Property Title As String
        Friend ReadOnly Property Value As Double
        Friend ReadOnly Property UnitName As String
        Friend ReadOnly Property SourceName As String
        Friend ReadOnly Property IsAvailable As Boolean
        Friend ReadOnly Property IsWarning As Boolean
        Friend ReadOnly Property Description As String

        Friend ReadOnly Property DisplayValue As String
            Get
                If Not IsAvailable Then Return "n/a"

                Dim rounded As Double = Math.Round(Value, 3)
                Dim text As String = rounded.ToString("0.###", CultureInfo.InvariantCulture)
                If String.IsNullOrWhiteSpace(UnitName) Then Return text

                Return text & " " & UnitName
            End Get
        End Property

    End Class

End Namespace
