// Created with MonoDevelop
//
//    Copyright (C) 2017 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.Common;
using static Hiperscan.Common.I18n.CatalogLocale;

namespace Hiperscan.AnalysisModule
{
    [DataContract]
    [Serializable]
    public class AnalysisServerInfo
    {
        public static AnalysisServerInfo Read(string fname)
        {
            return DataSerializer.Read<AnalysisServerInfo>(fname);
        }

        public static void Write(AnalysisServerInfo module_info, string fname)
        {
            DataSerializer.Write<AnalysisServerInfo>(module_info, fname);
        }

        public override string ToString()
        {
            string precise_name = "Ident";
            if (this.AnalysisType == AnalysisType.Quantification)
                precise_name = "Quantifier:";


            string info = String.Format("{0}ModuleInfo:", precise_name);



            info += string.Format("\nAssembly version:               {0}", this.Version.AssemblyVersion);
            info += string.Format("\nShort assembly version:         {0}", this.Version.ShortAssemblyVersion);
            info += string.Format("\n{1}Module full version:         {0}", this.Version.FullVersion, precise_name);
            info += string.Format("\n{1}Module version:              {0}", this.Version.ModuleVersion, precise_name);
            info += string.Format("\n{1}Module subversion:           {0}", this.Version.ModuleSubVersion, precise_name);
            info += string.Format("\nIs release:                     {0}", this.IsRelease);
            info += string.Format("\n{1}Module locale:               {0}", this.Locale, precise_name);
            info += string.Format("\n{1}Module GUID:                 {0}", this.Guid, precise_name);
            info += string.Format("\n{1}Module creation timestamp:   {0}", this.CreationTimestamp, precise_name);
            info += string.Format("\nModel type info:                {0}", this.ModelTypeInfo);
            info += string.Format("\nHostname:                       {0}",  Environment.MachineName);
            info += string.Format("\nTCP Port number:                {0}",  this.PortNumber);
            info += string.Format("\nInstallDate:                    {0}", this.InstallDate);


            foreach (string model_class_name in this.ModelClassNames)
            {
                info += string.Format("\n    => Model Class name: {0}",    model_class_name);
            }

            return info;
        }

        [DataMember] public AnalysisType AnalysisType { get; set; }
        [DataMember] public LocaleType Locale { get; set; }
        [DataMember] public AnalysisModuleVersion Version { get; set; }
        [DataMember] public Guid Guid { get; set; }

        [DataMember] public List<string> ModelClassNames { get; set; }
        [DataMember] public string ModelTypeInfo { get; set; }
        [DataMember] public DateTime CreationTimestamp { get; set; }
        [DataMember] public bool IsRelease { get; set; }
        [DataMember] public int PortNumber { get; set; }

        [DataMember] public DateTime InstallDate { get; set; }
    }
}

