// 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.Runtime.Serialization;


namespace Hiperscan.Spectroscopy
{

    [Serializable()]
    public class PcaMatch : System.IComparable<PcaMatch>, System.Runtime.Serialization.ISerializable
    {
        private string id;
        private int ranking;
        private double significance;
        private double confidence;
        private double correlation;
        private double distance;

        private PcaMatch()
        {
        }

        public PcaMatch(string name, double significance)
        {
            this.ranking = 0;
            this.id = name;
            this.significance = significance;
            this.confidence = 0.0;
            this.correlation = 0.0;
            this.distance = double.PositiveInfinity;
            this.ClassificationName = string.Empty;
            this.BackProjection = null;
        }

        public PcaMatch(SerializationInfo info, StreamingContext context)
        {
            this.id = (string)info.GetValue("Id", typeof(string));
            this.ranking = (int)info.GetValue("Ranking", typeof(int));
            this.significance = (double)info.GetValue("Significance", typeof(double));
            this.confidence = (double)info.GetValue("Confidence", typeof(double));
            this.correlation = (double)info.GetValue("Correlation", typeof(double));
            this.distance = (double)info.GetValue("Distance", typeof(double));
            this.ClassificationName = (string)info.GetValue("ClassificationName", typeof(string));
            this.BackProjection = (DataSet)info.GetValue("BackProjection", typeof(DataSet));
        }

        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("Id", this.id);
            info.AddValue("Ranking", this.ranking);
            info.AddValue("Significance", this.significance);
            info.AddValue("Confidence", this.confidence);
            info.AddValue("Correlation", this.correlation);
            info.AddValue("Distance", this.distance);
            info.AddValue("ClassificationName", this.ClassificationName);
            info.AddValue("BackProjection", this.BackProjection);
        }

        public int CompareTo(PcaMatch match)
        {
            if (match == null)
                return 1;

            return this.Significance.CompareTo(match.Significance);
        }

        public void SetRanking(int ranking)
        {
            this.ranking = ranking;
        }

        public void SetSignificance(double significance)
        {
            this.significance = significance;
        }

        public void SetConfidence(double confidence)
        {
            this.confidence = confidence;
        }

        public void SetCorrelation(double correlation)
        {
            this.correlation = correlation;
        }

        public void SetDistance(double distance)
        {
            this.distance = distance;
        }

        public override string ToString()
        {
            return string.Format("[PCAMatch: Name={0}, Ranking={1}, Significance={2}, Confidence={3}, Correlation={4}, Distance={5}]", Id, Ranking, Significance, Confidence, Correlation, Distance);
        }

        public string Id
        {
            get { return this.id; }
        }

        public int Ranking
        {
            get { return this.ranking; }
        }

        public double Significance
        {
            get { return this.significance; }
        }

        public double Confidence
        {
            get { return this.confidence; }
        }

        public double Correlation
        {
            get { return this.correlation; }
        }

        public double Distance
        {
            get { return this.distance; }
        }

        public string ClassificationName { get; set; }
        public DataSet BackProjection { get; set; }
    }
}