using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VSview
{
    public class Detector : BaseViewModel
    {

        #region Constructors
        /// <summary>
        /// Default constructor
        /// </summary>
        public Detector(MainViewModel mainViewModel)
        {
            ViewModel = mainViewModel;

            Calibration = new Calibration();
            Ionchamber = new Ionchamber();
            Range = new Range();
            Reject = new Reject();
            Settings = new Setting();
            Turbo = new Turbo();

            Communication = new DetectorCommunication(this);

            _lock = new object();
        }
        #endregion

        #region Private members
        //reference to main view model
        public MainViewModel ViewModel;

        //locking object
        private object _lock;
        #endregion

        #region Public properties

        /// <summary>
        /// Model of detector serial communication
        /// </summary>
        public DetectorCommunication Communication { get; set; }

        /// <summary>
        /// Detector calibration model
        /// </summary>
        public Calibration Calibration { get; set; }

        /// <summary>
        /// Detector ion chamber model
        /// </summary>
        public Ionchamber Ionchamber { get; set; }

        /// <summary>
        /// Detector range model
        /// </summary>
        public Range Range { get; set; }

        /// <summary>
        /// Detector reject model
        /// </summary>
        public Reject Reject { get; set; }

        /// <summary>
        /// Detector settings model
        /// </summary>
        public Setting Settings { get; set; }

        /// <summary>
        /// Detector turbo pump model
        /// </summary>
        public Turbo Turbo { get; set; }
        #endregion
        

        /// <summary>
        /// Method for creating message and adding it to the detector send queue
        /// </summary>
        /// <param name="text"> text which should be send to HLD </param>
        /// <param name="isVisible"> if text should be visible in log (also response from detector) </param>
        public void SendToDetector(string text, bool isVisible = false)
        {
            lock (_lock)
            {
                if (Communication.SendQueue != null)
                {
                    Message message = new Message(text, isVisible);
                    Communication.SendQueue.AddLast(message);
                }
            }
        }
    }
}
