// 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.ApoIdentCommon.ApoConfig.Enums;

namespace Hiperscan.ApoIdentCommon.ApoConfig.Cache
{
    public class GracePeriodEntry
    {
        private const string SEPARATOR = "::";

        public GracePeriodEntry()
        {
        }

        public GracePeriodEntry(string value)
        {
            string[] values = value.Split(new string[] { GracePeriodEntry.SEPARATOR }, StringSplitOptions.None);
            this.QuantityValue = values[0] ?? String.Empty;
            this.QuantityUnit = (GracePeriodTypes)Enum.Parse(typeof(GracePeriodTypes), values[1]);
        }

        public GracePeriodEntry Clone()
        {
            GracePeriodEntry tmp = new GracePeriodEntry();
            tmp.QuantityUnit = this.QuantityUnit;
            tmp.QuantityValue = this.QuantityValue;

            return tmp;
        }

        public override string ToString()
        {
            return String.Format("{0}{1}{2}",
                                 this.QuantityValue ?? String.Empty,
                                 GracePeriodEntry.SEPARATOR,
                                 this.QuantityUnit.ToString());
        }

        public GracePeriodTypes QuantityUnit { get; set; } = GracePeriodTypes.None;
        public string QuantityValue { get; set; } = String.Empty;
    }
}
