// Created with MonoDevelop
//
//    QuickStep: Acquire, view and identify spectra 
//    Copyright (C) 2022, 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.AnalysisModule;
using Hiperscan.ApoIdentCommon.ApoConfig.IO;

namespace Hiperscan.ApoIdentCommon.ApoConfig.Cache
{
    public class AdditionalTest : CacheManagement<AdditionalTest, string>
    {
        public AdditionalTest()
        {
            this.Entries = new EntryWriter<AdditionalTest>();
#pragma warning disable RECS0021 // Warnt vor Aufrufen virtueller Memberfunktionen im Konstruktor.
            this.Reset();
#pragma warning restore RECS0021 // Warnt vor Aufrufen virtueller Memberfunktionen im Konstruktor.
        }

        public override void Reset()
        {
            base.Reset();
            this.InsertIntoProtocol = false;
            this.TruePositive = false;
            this.CustomerEvalution = false;
            this.IsGreenSubstance = false;
        }

        protected override string ConvertFromString(string value)
        {
            return value;
        }

        protected override string ConvertToString(string value)
        {
            return value;
        }

        protected override string GetDefaultValue()
        {
            return String.Empty;
        }

        protected override bool StateChanged()
        {
            return this.CurrentValue != this.InitialValue;
        }

        public AdditionalTest Clone()
        {
            AdditionalTest tmp = new AdditionalTest();
            tmp.IsMandatoryForComplementaryTest = this.IsMandatoryForComplementaryTest;
            tmp.Entries = this.Entries;
            tmp.Reset();

            return tmp;
        }

        protected override string CloneCurrentValue()
        {
            return this.CurrentValue;
        }

        public string ProtocolText
        {
            get
            {
                if (this.InsertIntoProtocol)
                    return this.CurrentValue;

                return String.Empty;
            }
        }

        public bool ProtocolCustomerEvaluation
        {
            get
            {
                if (this.IsGreenSubstance && this.TruePositive == true)
                    return true;

                if (this.InsertIntoProtocol)
                    return this.CustomerEvalution;

                return false;
            }
        }

        public bool IsUserInputValid
        {
            get
            {
                if (this.IsMandatoryForComplementaryTest == false)
                    return true;

                if (this.IsThirdPartyProtocol == true)
                    return true;

                if (this.IsGreenSubstance && this.TruePositive == true)
                    return true;

                return String.IsNullOrEmpty(this.ProtocolText) == false;
            }
        }

        public bool IsMandatoryForComplementaryTest { get; set; } = true;
        public bool IsThirdPartyProtocol { get; set; }
        public bool InsertIntoProtocol { get; set; }
        public bool TruePositive { get; set; }
        public bool CustomerEvalution { get; set; }
        public bool IsGreenSubstance { get; set; }
        public AnalysisType AnalysisType { get; set; }
        public bool QuantificationConfirmed { get; set; }
    }
}
