// 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 class ProcessingReferences
    {
        private string creator = string.Empty;

        protected Spectrum processing_black = null;
        protected Spectrum processing_white = null;
        protected Spectrum processing_sample_insert_white = null;
        protected Spectrum processing_transflectance_insert = null;
        protected Spectrum corrected_oxide_of_reference = null;
        protected Spectrum corrected_oxide_of_sample = null;
        protected WavelengthCorrection wavelength_correction_of_references = null;
        protected WavelengthCorrection wavelength_correction_of_sample = null;

        protected DataSet processing_external_background = null;
        protected DataSet processing_external_dark = null;

        protected ExternalBackgroundType external_background_type = ExternalBackgroundType.Unknown;

        protected ProcessingReferences(string creator)
        {
            this.creator = creator;
        }

        public ProcessingReferences Clone()
        {
            return new ProcessingReferences(this.creator)
            {
                processing_black                     = this.processing_black?.Clone(),
                processing_sample_insert_white       = this.processing_sample_insert_white?.Clone(),
                processing_white                     = this.processing_white?.Clone(),
                processing_transflectance_insert     = this.processing_transflectance_insert?.Clone(),
                corrected_oxide_of_sample            = this.corrected_oxide_of_sample?.Clone(),
                corrected_oxide_of_reference         = this.corrected_oxide_of_reference?.Clone(),
                wavelength_correction_of_sample      = new WavelengthCorrection(this.wavelength_correction_of_sample),
                wavelength_correction_of_references  = new WavelengthCorrection(this.wavelength_correction_of_references),
                processing_external_background       = new DataSet(this.processing_external_background),
                processing_external_dark             = new DataSet(this.processing_external_dark),
                external_background_type             = this.ExternalBackgroundType
            };
        }

        protected void ResetProcessingReferences()
        {
            this.processing_black                        = null;
            this.processing_sample_insert_white          = null;
            this.processing_white                        = null;
            this.processing_transflectance_insert        = null;
            this.corrected_oxide_of_sample                = null;
            this.corrected_oxide_of_reference             = null;
            this.wavelength_correction_of_sample         = null;
            this.wavelength_correction_of_references     = null;
            this.processing_external_background          = null;
            this.processing_external_dark                = null;
        }

        public string Creator { get => this.creator; }

        public virtual Spectrum ProcessingBlack { get => this.processing_black; }

        public virtual Spectrum ProcessingWhite { get => this.processing_white; }

        public virtual Spectrum ProcessingSampleInsertWhite { get => this.processing_sample_insert_white; }

        public virtual Spectrum ProcessingTransflectanceInsert { get => this.processing_transflectance_insert; }

        public virtual Spectrum CorrectedOxideOfReferences { get => this.corrected_oxide_of_reference; }

        public virtual Spectrum CorrectedOxideOfSample { get => this.corrected_oxide_of_sample; }

        public virtual WavelengthCorrection WavelengthCorrectionOfReferences { get => this.wavelength_correction_of_references; }

        public virtual WavelengthCorrection WavelengthCorrectionOfSample { get => this.wavelength_correction_of_sample; }

        public virtual DataSet ProcessingBackground { get => this.processing_external_background; }

        public virtual DataSet ProcessingDark { get => this.processing_external_dark; }

        public virtual ExternalBackgroundType ExternalBackgroundType { get => this.external_background_type; }

        public bool IsFluid
        {
            get
            {
                return this.external_background_type == ExternalBackgroundType.TransflectanceWhite;
            }
        }
    }
}
