// 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 Hiperscan.AnalysisModule.Identification;
using Hiperscan.ApoIdentCommon.ApoConfig.IO;

namespace Hiperscan.ApoIdentCommon.ApoConfig.Cache
{
    public class BakMarking : CacheManagement<BakMarking, BAKMarkingState>
    {
        public BakMarking()
        {
            this.Entries = new EntryWriter<BakMarking>();
            this.Reset();
        }

        public BakMarking Clone()
        {
            BakMarking tmp = new BakMarking();
            tmp.IsActive = this.IsActive;
            tmp.Entries = this.Entries;
            tmp.Reset();
            return tmp;
        }

        protected override BAKMarkingState GetDefaultValue()
        {
            return BAKMarkingState.None;
        }

        protected override BAKMarkingState ConvertFromString(string value)
        {
            if (value.ToLower().Contains(BAKMarkingState.Red.ToString().ToLower()))
                return BAKMarkingState.Red;

            BAKMarkingState tmp = BAKMarkingState.None;

            if (value.ToLower().Contains(BAKMarkingState.Blue.ToString().ToLower()))
                tmp |= BAKMarkingState.Blue;

            if (value.ToLower().Contains(BAKMarkingState.Orange.ToString().ToLower()))
                tmp |= BAKMarkingState.Orange;

            if (value.ToLower().Contains(BAKMarkingState.Yellow.ToString().ToLower()))
                tmp |= BAKMarkingState.Yellow;

            return tmp;
        }

        protected override string ConvertToString(BAKMarkingState value)
        {
            return value.ToString();
        }

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

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

        public bool IsActive { get; set; }
    }
}
