// Created with MonoDevelop
//
//    Copyright (C) 2023 Hiperscan GmbH Dresden, Germany
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.


using System;

namespace Hiperscan.SGS.Benchtop.TemperatureControl
{
    public class DetectorTemperature
    {
        public DetectorTemperature(int history_count = 10, int interval_sec = 300)
        {
            this.TransisitorTemperature = new Temperature(history_count, interval_sec);
            this.AmplifierTemperature = new Temperature(history_count, interval_sec);
        }

        public DetectorTemperature Clone()
        {
            return new DetectorTemperature()
            {
                AmplifierTemperature = this.AmplifierTemperature.Clone(),
                TransisitorTemperature = this.TransisitorTemperature.Clone(),
                Enable = this.Enable,
                Reset = this.Reset,
                Sensor = this.Sensor,
                State = this.State,
                SetTemperature = this.SetTemperature,
                PidControl = this.PidControl.Clone()
            };
        }

        public override string ToString()
        {
            String data = "Detector Temperature Data:\n";
            data += String.Format("\tSet temperature       : {0:F2}°C\n", this.SetTemperature);
            data += String.Format("\tTransistor temperature: {0}\n", this.TransisitorTemperature);
            data += String.Format("\tAmplifier temperature : {0}\n", this.AmplifierTemperature);
            data += String.Format("\tHeater state          : {0}\n", this.State);
            data += String.Format("\tSensor                : {0}\n", this.Sensor);
            data += String.Format("\tEnable                : {0}\n", this.Enable);
            data += String.Format("\tReset                 : {0}\n", this.Reset);
            data += String.Format("\tHeatertPidControl     : {0}\n", this.PidControl);

            return data;
        }

        public double SetTemperature { get; set; } = double.NaN;
        public bool Enable { get; set; } = false;
        public bool Reset { get; set; } = false;
        public HeaterState State { get; set; } = HeaterState.Off;
        public DetectorSensorType Sensor { get; set; } = DetectorSensorType.Transistor;

        public Temperature TransisitorTemperature { get; protected set; }
        public Temperature AmplifierTemperature { get; protected set; }
        public PidControl PidControl { get; protected set; } = new PidControl();
    }
}
