// Created with MonoDevelop
//
//    Copyright (C) 2018 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;
using System.Runtime.Serialization;


namespace Hiperscan.Spectroscopy
{

    [Serializable()]
    public class DarkIntensity : System.Runtime.Serialization.ISerializable
    {
        private double intensity;
        private double sigma;
        private DateTime date_time;

        public DarkIntensity(double intensity, double sigma)
        {
            this.intensity = intensity;
            this.sigma = sigma;
            this.date_time = DateTime.Now;
        }

        public DarkIntensity(Spectrum spectrum)
        {
            spectrum = spectrum.Clone();
            spectrum.ApplyCorrectionsToRawData(CorrectionMask.WavelengthLimits);
            this.intensity = spectrum.RawIntensity.YMean();
            this.sigma = spectrum.RawIntensity.YSigma();
            this.date_time = spectrum.Timestamp;
        }

        public DarkIntensity(DarkIntensity di)
        {
            this.intensity = di.Intensity;
            this.sigma = di.Sigma;
            this.date_time = di.DateTime;
        }

        private DarkIntensity(SerializationInfo info, StreamingContext context)
        {
            this.intensity = (double)info.GetValue("Intensity", typeof(double));
            this.sigma = (double)info.GetValue("Sigma", typeof(double));
            this.date_time = (DateTime)info.GetValue("DateTime", typeof(DateTime));
        }

        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("Intensity", this.intensity);
            info.AddValue("Sigma", this.sigma);
            info.AddValue("DateTime", this.date_time);
        }

        public void SetIntensity(double val)
        {
            this.intensity = val;
        }

        public void SetSigma(double val)
        {
            this.sigma = val;
        }

        public void SetDateTime(DateTime val)
        {
            this.date_time = val;
        }

        public double Intensity
        {
            get { return this.intensity; }
        }

        public double Sigma
        {
            get { return this.sigma; }
        }

        public DateTime DateTime
        {
            get { return this.date_time; }
        }
    }
}