// Created with MonoDevelop
//
//    Copyright (C) 2024 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 Hiperscan.Spectroscopy;

namespace Hiperscan.Spectroscopy.Processing
{
    public partial class ReferenceWheelProcessor
    {
        public bool NoOrdinateCorrection { get; set; }

        private bool HasTemperatureDependedCorrection
        {
            get
            {
                return this.linear_distortion != null && this.correction_vector != null;
            }
        }

        public Spectrum InternalDark
        {
            get
            {
                return this.internal_dark;
            }
            set
            {
                this.internal_dark = value?.Clone();
                this.ConfigureLimitBandwidth(this.internal_dark);
                if (value != null)
                    this.sample_dark_intensity = new DarkIntensity(this.internal_dark);
                else
                    this.sample_dark_intensity = null;

                this.recalc_internal_oxid = true;
                this.recalc_internal_white = true;
                this.ResetExternalReferences();
            }
        }

        public Spectrum InternalDarkReference
        {
            get
            {
                return this.internal_dark_reference;
            }
            set
            {
                this.internal_dark_reference = value?.Clone();
                this.ConfigureLimitBandwidth(this.internal_dark_reference);
                if (value != null)
                    this.reference_dark_intensity = new DarkIntensity(this.internal_dark_reference);
                else
                    this.reference_dark_intensity = null;
                    
                this.recalc_internal_oxid_reference = true;
                this.recalc_internal_white_reference = true;
                this.ResetExternalReferences();
            }
        }

        public Spectrum InternalWhite
        {
            get
            {
                if (this.recalc_internal_white)
                {
                    this.recalc_internal_white = false;
                }
                return this.internal_white;
            }
            set
            {
                this.internal_white = value?.Clone();
                this.sample_background = value?.Clone();
                this.ConfigureLimitBandwidth(this.internal_white);
                this.recalc_internal_oxid = true;
                this.ResetExternalReferences();
            }
        }

        public Spectrum InternalWhiteReference
        {
            get
            {
                if (this.recalc_internal_white_reference)
                {
                    this.recalc_internal_white_reference = false;
                }
                return this.internal_white_reference;
            }
            set
            {
                this.internal_white_reference = value?.Clone();
                this.reference_background = value?.Clone();
                this.ConfigureLimitBandwidth(this.internal_white_reference);
                this.recalc_internal_oxid_reference = true;
                this.ResetExternalReferences();
            }
        }

        public Spectrum InternalOxid
        {
            get
            {
                if (this.recalc_internal_oxid && this.internal_oxid != null)
                {
                    if (this.sample_dark_intensity != null)
                        this.internal_oxid.DarkIntensity = new DarkIntensity(this.sample_dark_intensity);
                    if (this.internal_white != null)
                        this.internal_oxid.Reference = this.internal_white.Clone();
                    this.recalc_internal_oxid = false;
                }
                return this.internal_oxid;
            }
            set
            {
                this.internal_oxid = value?.Clone();
                this.ConfigureLimitBandwidth(this.internal_oxid);
                this.ResetExternalReferences();
            }
        }

        public Spectrum InternalOxidReference
        {
            get
            {
                if (this.recalc_internal_oxid_reference && this.internal_oxid_reference != null)
                {
                    if (this.reference_dark_intensity != null)
                        this.internal_oxid_reference.DarkIntensity = new DarkIntensity(this.reference_dark_intensity);
                    if (this.internal_white_reference != null)
                        this.internal_oxid_reference.Reference = this.internal_white_reference.Clone();
                    this.recalc_internal_oxid_reference = false;
                }
                return this.internal_oxid_reference;
            }
            set
            {
                this.internal_oxid_reference = value?.Clone();
                this.ConfigureLimitBandwidth(this.internal_oxid_reference);
                this.ResetExternalReferences();
            }
        }
    }
}
