//                           UNCLASSIFIED
/*-------------------------------------------------------------------------
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
COMPANY.

THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
GOVERNMENT.

UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
-------------------------------------------------------------------------*/

using System;
using System.Threading;
using NLog;
using Raytheon.Common;

namespace Raytheon.Instruments
{
   /// <summary>
   /// Temperature monitor class used to interact with the temperature sensor.
   /// </summary>
   public class TempMonitorSim : ITempMonitor
   {
      #region PrivateMembers

      private object m_sync = new object();

      private readonly ILogger _logger;

      private readonly IConfigurationManager _configurationManager;
      private readonly IConfiguration _configuration;

      public string DetailedStatus => throw new NotImplementedException();

      public bool DisplayEnabled { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
      public bool FrontPanelEnabled { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

      public InstrumentMetadata Info => throw new NotImplementedException();

      public string Name { get; set; }

      public SelfTestResult SelfTestResult => throw new NotImplementedException();

      public State Status => throw new NotImplementedException();

      #endregion

      #region PrivateFunctions
      /// <summary>
      /// Destructor
      /// </summary>
      ~TempMonitorSim()
      {
         Dispose(false);
      }

      /// <summary>
      /// Dispose of this object's resources
      /// </summary>
      /// <param name="disposing">Currently disposing</param>
      protected virtual void Dispose(bool disposing)
      {
      }

      #endregion

      #region PublicFunctions

      /// <summary>
      /// TempMonitorSim factory constructor
      /// </summary>
      /// <param name="deviceName"></param>
      /// <param name="configurationManager"></param>
      public TempMonitorSim(string deviceName, IConfigurationManager configurationManager)
      {
         Name = deviceName;

         _logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");

         _configurationManager = configurationManager;
         _configuration = _configurationManager.GetConfiguration(Name);
      }

      /// <summary>
      /// Constructor for the temperature sensor
      /// </summary>
      /// <param name="deviceName">the name</param>
      /// <param name="ipAddress">IP Address of the equipment</param>
      /// <param name="port">Port of the equipment</param>
      public TempMonitorSim(string deviceName)
      {
         Name = deviceName;
         _logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
      }


      // This code added to correctly implement the disposable pattern.
      [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")]
      public void Dispose()
      {
         lock (m_sync)
         {
            Dispose(true);

            GC.SuppressFinalize(this);
         }
      }

      /// <summary>
      /// Returns the current temperature read by temperature sensor
      /// </summary>
      /// <returns>The current Temperature reading</returns>
      public double ReadTemperature()
      {
         lock (m_sync)
         {
            double max = 20.0;

            double min = 30.0;

            Random rnd = new Random();

            double seed = rnd.NextDouble();

            double dataToReturn = (seed * (max - min)) + min;

            Thread.Sleep(100);

            return dataToReturn;
         }
      }

      public bool ClearErrors()
      {
         throw new NotImplementedException();
      }

      public void Initialize()
      {
         throw new NotImplementedException();
      }

      public SelfTestResult PerformSelfTest()
      {
         throw new NotImplementedException();
      }

      public void Reset()
      {
         throw new NotImplementedException();
      }

      public void Shutdown()
      {
         throw new NotImplementedException();
      }

      #endregion
   }
}
