using CommunityToolkit.Mvvm.ComponentModel;

namespace ConeCalorimeter.ViewModels;

public sealed class MetricDisplayViewModel : ObservableObject
{
    private string _valueText = "";

    public MetricDisplayViewModel(string label, string unit = "")
    {
        Label = label;
        Unit = unit;
    }

    public string Label { get; }

    public string Unit { get; }

    public string ValueText
    {
        get => _valueText;
        private set => SetProperty(ref _valueText, value);
    }

    public void SetValue(double value, string format = "0.00")
    {
        if (!double.IsFinite(value))
        {
            ValueText = string.Empty;
            return;
        }

        ValueText = value.ToString(format);
    }

    public void SetValue(int value)
    {
        if (value < 0)
        {
            ValueText = string.Empty;
            return;
        }

        ValueText = value.ToString();
    }
}
