//                           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>
   /// Flow Meter Sim Class
   /// </summary>
   public class FlowMeterSim : IFlowMeter
   {
      #region PrivateMembers
      private static object _sync = new object();

      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();

      /// <summary>
      /// Destructor
      /// </summary>
      ~FlowMeterSim()
      {
         Dispose(false);
      }

      private readonly ILogger _logger;

      private readonly IConfigurationManager _configurationManager;
      private readonly IConfiguration _configuration;

      #endregion

      #region PrivateFunctions

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

      #region PublicFunctions

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

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

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

      /// <summary>
      /// 
      /// </summary>
      /// <param name="name"></param>
      public FlowMeterSim(string name)
      {
         Name = name;
         _logger = LogManager.GetCurrentClassLogger();
      }

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

            GC.SuppressFinalize(this);
         }
      }

      /// <summary>
      /// Query the flow rate from the flow meter
      /// </summary>
      /// <returns>the flow rate.</returns>
      public double ReadFlow()
      {
         lock (_sync)
         {
            double max = 0.15;

            double min = .35;

            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
   }
}
