// Created with MonoDevelop
//
//    QuickStep: Acquire, view and identify spectra 
//    Copyright (C) 2018 Thomas Klose & Torsten Schache, 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.IdentModule;


namespace Hiperscan.Extensions.ApoIdent
{
    public enum SubstanceCategory
    {
        None,
        UserDefined,
        NotMeasurable,
        Classifiaction,
        SingleSubstance,
    }

    public class SubstanceListAutoCompletionEntry : IComparable<SubstanceListAutoCompletionEntry>
    {
        public int CompareTo(SubstanceListAutoCompletionEntry other)
        {
            int lhs = (int) this.SubstanceCategory;
            int rhs = (int) other.SubstanceCategory;

            if (lhs < 3 && rhs > 2)
                return 1;

            if (rhs < 3 && lhs > 2)
                return -1;

            return this.Name.CompareTo(other.Name);
        }

        public string Name                              {get; set;}
        public SubstanceCategory  SubstanceCategory   {get; set;} = SubstanceCategory.UserDefined;

        public static SubstanceCategory ConvertToSubstanceCategory(ClassificationInfo classification_info)
        {
            if (classification_info == null)
                return SubstanceCategory.None;
            
            if (classification_info.IsUserDefined == true)
                return SubstanceCategory.UserDefined;

            if (classification_info.IsNirMeasurable == false)
                return SubstanceCategory.NotMeasurable;

            if (classification_info.ClassificationType == ClassificationType.NonMultiple)
                return SubstanceCategory.SingleSubstance;

            if (classification_info.Substances.Count == 1)
                return SubstanceCategory.SingleSubstance;

            return SubstanceCategory.Classifiaction;
        }
    }
}
