// 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.Runtime.Serialization;
using System.Text.RegularExpressions;
using Hiperscan.Unix;

namespace Hiperscan.AnalysisModule
{
    [DataContract]
    [Serializable]
    public class AnalysisModuleVersion
    {
        private AnalysisModuleVersion()
        {
        }

        public AnalysisModuleVersion(string full_version)
        {
            Regex regex = new Regex(@"^\d+\.\d+\.\d+-\d{4}-\d{2}-\d{4,6}$");

            if (regex.Match(full_version).Success == false)
                throw new ArgumentException(Catalog.GetString("IdentServer ID has invalid format."));

            this.FullVersion = full_version;
        }

        public AnalysisModuleVersion(string assembly_version, string module_version, string module_subversion) :
            this (assembly_version + "-" + module_version + "-" + module_subversion)
        {

        }

        public string ModuleVersion
        {
            get
            {
                string[] tmp = this.FullVersion.Split(new char[] { '-' });
                return this.ShortAssemblyVersion + "-" + tmp[1] + "-" + tmp[2];
            }
        }

        public string ModuleSubVersion
        {
            get { return this.FullVersion.Split('-')[3]; }
        }

        public string AssemblyVersion
        {
            get { return this.FullVersion.Split('-')[0]; }
        }

        public string ShortAssemblyVersion
        {
            get
            {
                string[] tmp = this.AssemblyVersion.Split(new char[] { '.' });
                return tmp[0] + "." + tmp[1];
            }
        }

        public string AssemblyMajorVersion
        {
            get { return this.ShortAssemblyVersion.Split(new char[] { '.' })[0]; }
        }

        public string AssemblyMinorVersion
        {
            get { return this.ShortAssemblyVersion.Split(new char[] { '.' })[1]; }
        }

        [DataMember] public string FullVersion { get; private set; }
    }
}
