using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using Ion.Sdk.Idi;

namespace Ion.Sdk.DemoApp.Views.ViewModels
{
    public class MeasurementViewModel : TreeNodeViewModel
    {
        public Sdk.Idi.Measurement Model { get; }
        public bool IsLocked => !(Model is EmptyMeasurement);

        public bool HasParameters { get; }
        public bool HasLimits { get; }
        public bool HasResults { get; }
        public bool HasGraphs { get; }

        public MeasurementViewModel(Measurement model)
        {
            Model = model;
            HasParameters = model.HasParameters;
            HasLimits = model.HasLimits;
            HasResults = model.HasResults;
            HasGraphs = model.HasGraphs;
        }
    }

    public sealed class MeasurementToViewModelConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is Measurement measurement)
                return new ViewModels.MeasurementViewModel(measurement);
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (value as ViewModels.MeasurementViewModel)?.Model;
        }
    }
}
