using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace VSview
{
    public class MeasurementViewModel : BaseViewModel
    {
        /// <summary>
        /// Reference to main view model
        /// </summary>
        private MainViewModel ViewModel;

        #region Constructors

        /// <summary>
        /// Default constructor
        /// </summary>
        public MeasurementViewModel(MainViewModel mainViewModel)
        {
            //Add reference to main view model
            ViewModel = mainViewModel;
            //create command list
            SetupCommands();

            Displays = new List<DisplayModel>();

            Displays.Add(new DisplayModel());
            Displays.Add(new DisplayModel());
            Displays.Add(new DisplayModel());
            Displays.Add(new DisplayModel());

            //Add static options to display list
            DisplayList = new ObservableCollection<string>() {"Empty", "Leakrate", "TP pressure", "", "", "", ""};
        }

        #endregion

        #region Public properties

        /// <summary>
        /// Selected index of tabcontrol
        /// </summary>
        public int TabcontrolIndex { get; set; }

        /// <summary>
        /// Collection of displays
        /// </summary>
        public List<DisplayModel> Displays { get; set; }

        /// <summary>
        /// List of all availliable displed values
        /// </summary>
        public ObservableCollection<string> DisplayList { get; set; }
        #endregion

        #region Commands
        /// <summary>
        /// Collection of measurement commands
        /// </summary>
        public Dictionary<string, RelayCommand> Command { get; set; }

        /// <summary>
        /// Method for creating collection of commands
        /// </summary>
        private void SetupCommands()
        {
            Command = new Dictionary<string, RelayCommand>();

            Command.Add("Zero", new RelayCommand(Zero));
            Command.Add("Test", new RelayCommand(Test));
            Command.Add("Vent", new RelayCommand(Vent));
            Command.Add("ToggleDisplay", new RelayCommand(ToggleDisplay));
        }

        /// <summary>
        /// Method for setting leak value to 0
        /// </summary>
        /// <param name="obj"></param>
        private void Zero(object obj)
        {
            ViewModel.Detector.SendToDetector("ZERO", true);
        }

        /// <summary>
        /// Method for changing detector state to TEST
        /// </summary>
        /// <param name="obj"></param>
        private void Test(object obj)
        {
            if (ViewModel.Detector.Settings.DetectorMode == "FINE TEST" || ViewModel.Detector.Settings.DetectorMode == "TEST" || ViewModel.Detector.Settings.DetectorMode == "ROUGHING")
                ViewModel.Detector.SendToDetector("KEEP", true);
            else
                ViewModel.Detector.SendToDetector("ROUGH", true);
        }

        /// <summary>
        /// Method for changing detector state to VENTED
        /// </summary>
        /// <param name="obj"></param>
        private void Vent(object obj)
        {
            ViewModel.Detector.SendToDetector("VENT", true);
        }

        private void ToggleDisplay(object obj)
        {
            var binding = new Binding();


        }


        #endregion
    }
}
