// Created with MonoDevelop
//
//    Copyright (C) 2024 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.Runtime.Serialization;
using Hiperscan.AnalysisModule.Authentification;
using Hiperscan.AnalysisModule.Identification;
using Hiperscan.Spectroscopy.Method;

namespace Hiperscan.AnalysisModule.Quantification
{
    [DataContract]
    [Serializable]
    public class QuantifierModelClass : IModelClass
    {
        public IdentModelClass Convert()
        {
            IdentModelClass ident_model_class = new IdentModelClass();
            ident_model_class.Id = this.Id;
            ident_model_class.Name = this.Name;
            ident_model_class.AccessDefinitionName = this.AccessDefinitionName;
            ident_model_class.DefaultSupplierName = this.DefaultSupplierName;
            ident_model_class.SubstanceType = this.SubstanceType;
            ident_model_class.HasValidationDocument = this.HasValidationDocument;
            ident_model_class.HasAdditionalTestDocument = this.HasAdditionalTestDocument;
            ident_model_class.DatabaseInfo = this.DatabaseInfo.Clone();

            IdentClassification ident_classification = new IdentClassification();
            ident_classification.Id = this.Id;
            ident_classification.Name = this.SubstanceName;
            ident_classification.ClassificationType = ClassificationType.Single;

            IdentSubstance ident_substance = new IdentSubstance();
            ident_substance.Id = this.Id;
            ident_substance.PrimaryDefaultName = this.SubstanceName;
            ident_substance.PrimaryLatinName = this.LatinName;
            ident_substance.PdfLinkAdditionalTest = this.PdfFileAdditionalTest;
            ident_substance.BAKMarking = BAKMarkingState.None;
            ident_substance.CanInsert = false;
            ident_substance.IsVisible = true;

            foreach(QuantifierContent content in this.Contents)
            {
                IdentSample ident_sample = new IdentSample();
                ident_sample.Id = content.Id;
                ident_sample.Info = content.Name;

                ident_substance.Samples.Add(ident_sample);
            }

            ident_classification.Substances.Add(ident_substance);
            ident_model_class.Classifications.Add(ident_classification);
            ident_model_class.InitResolver();

            return ident_model_class;
        }

        [DataMember] public string DefaultSupplierName { get; set; }
        [DataMember] public string AccessDefinitionName { get; set; }
        [DataMember] public string Name { get; set; }
        [DataMember] public string Id { get; set; }
        [DataMember] public SubstanceType SubstanceType { get; set; }
        [DataMember] public bool HasValidationDocument { get; set; }
        [DataMember] public bool HasAdditionalTestDocument { get; set; }
        [DataMember] public string SubstanceName { get; set; }
        [DataMember] public string LatinName { get; set; }
        [DataMember] public string PdfFileAdditionalTest { get; set; }

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

        [IgnoreDataMember] public AccessDatabaseInfo DatabaseInfo { get; set; }
    }
}
