// Created with MonoDevelop
//
//    Copyright (C) 2018 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 System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using Hiperscan.AnalysisModule.Identification.ValidationReportInfo;

namespace Hiperscan.AnalysisModule.Identification
{
    [DataContract]
    [Serializable]
    public class IdentClassification
    {
        public IdentClassification Clone()
        {
            IdentClassification tmp = new IdentClassification();
            tmp.Id = this.Id;
            tmp.Name = this.Name;
            tmp.ClassificationType = this.ClassificationType;
            tmp.Substances = this.Substances.Select(s => s.Clone()).ToList();
            tmp.ReportInfo = this.ReportInfo;

            return tmp;
        }

        public Dictionary<string, string> GetSubstanceNames(IdentSubstance exclude_substance = null)
        {
            Dictionary<string, string> value = new Dictionary<string, string>();

            foreach (IdentSubstance substance in this.Substances)
            {
                if (substance.IsVisible == false)
                    continue;

                if (exclude_substance != null && exclude_substance.Id == substance.Id)
                    continue;

                value.Add(substance.PrimaryDefaultName, substance.PrimaryLatinName);
            }

            return value;
        }

        public bool IsUserDefined
        {
            get
            {
                return this.ClassificationType == ClassificationType.UserDefined;
            }
        }

        public bool IsNirMeasurable
        {
            get
            {
                return this.ClassificationType != ClassificationType.UserDefined &&
                           this.ClassificationType != ClassificationType.NotMeasurable;
            }
        }

        [DataMember] public string Id { get; set; }
        [DataMember] public string Name { get; set; }
        [DataMember] public ClassificationType ClassificationType { get; set; }
        [DataMember] public ClassificationReportInfo ReportInfo { get; set; }

        [DataMember] public List<IdentSubstance> Substances { get; set; }
            = new List<IdentSubstance>();
    }
}