using CareFusion.Lib.StorageSystem.Wwks2.Messages.OutputDestination;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CareFusion.ITSystemSimulator
{
    public class OutputDestinationStateIndicationModel
    {
        #region Members
        /// <summary>
        /// Holds the state indication responses model.
        /// </summary>
        private DataTable _stateIndicationResponsesModel = new DataTable();

        /// <summary>
        /// Holds the buttons pressed data model.
        /// </summary>
        private DataTable _buttonsPressedModel = new DataTable();
        #endregion

        #region Properties
        /// <summary>
        /// Gets the currently active state indication responses.
        /// </summary>
        public DataTable StateIndicationResponses
        {
            get { return _stateIndicationResponsesModel; }
        }

        /// <summary>
        /// Gets the currently active buttons pressed model.
        /// </summary>
        public DataTable ButtonsPressed
        {
            get { return _buttonsPressedModel; }
        }
        #endregion

        #region Constructor
        /// <summary>
        /// Initializes a new instance of the <see cref="OutputDestinationStateIndicationModel"/> class.
        /// </summary>
        public OutputDestinationStateIndicationModel()
        {
            DataColumn columnOutputDestination = _stateIndicationResponsesModel.Columns.Add();
            columnOutputDestination.DataType= typeof(string);
            columnOutputDestination.ColumnName= "Timestamp";

            columnOutputDestination = _stateIndicationResponsesModel.Columns.Add();
            columnOutputDestination.DataType = typeof(int);
            columnOutputDestination.ColumnName = "Output";

            columnOutputDestination = _stateIndicationResponsesModel.Columns.Add();
            columnOutputDestination.DataType = typeof(string);
            columnOutputDestination.ColumnName = "Result";

            columnOutputDestination = _stateIndicationResponsesModel.Columns.Add();
            columnOutputDestination.DataType = typeof(string);
            columnOutputDestination.ColumnName = "Text";

            DataColumn columnButtonsPressed = _buttonsPressedModel.Columns.Add();
            columnButtonsPressed.DataType = typeof(string);
            columnButtonsPressed.ColumnName = "Timestamp";

            columnButtonsPressed = _buttonsPressedModel.Columns.Add();
            columnButtonsPressed.DataType = typeof(int);
            columnButtonsPressed.ColumnName = "Output";
        }
        #endregion

        #region Methods
        /// <summary>
        /// Updates the state indication model.
        /// </summary>
        /// <param name="response">The output destination state indication set response.</param>
        public void UpdateStateIndicationResponse(IOutputDestinationStateIndicationSetResponse response)
        {     
            DataRow row = _stateIndicationResponsesModel.NewRow();
            
            row["Timestamp"] = DateTime.Now.ToString("HH:mm:ss");
            row["Output"] = response.OutputDestination;
            row["Result"] = response.Result;
            row["Text"] = response.Text;

            _stateIndicationResponsesModel.Rows.Add(row);            
        }

        /// <summary>
        /// Updates the buttons pressed model.
        /// </summary>
        /// <param name="outputDestination">The number of the output destination.</param>
        public void UpdateButtonsPressed(int outputDestination)
        {
            DataRow row = _buttonsPressedModel.NewRow();

            row["Timestamp"] = DateTime.Now.ToString("HH:mm:ss");
            row["Output"] = outputDestination;

            _buttonsPressedModel.Rows.Add(row);
        }
        #endregion
    }
}
