using System;
using System.Text.RegularExpressions;
using static Hiperscan.Common.I18n.CatalogLocale;

namespace Hiperscan.Common.RegistryManagement
{
    public class HSRegistryEntry
    {
        public static readonly Version NO_VERSION = new Version(0, 0, 0);

        public HSRegistryEntry()
        {
        }

        public Version AssemblyVersion
        {
            get
            {
                try
                {
                    Regex regex = new Regex(@"\d+\.\d+\.\d+");
                    string version = regex.Match(this.FullVersion).Value;
                    return new Version(version);
                }
                catch(Exception)
                {
                    try
                    {
                        Regex regex = new Regex(@"\d+\.\d+");
                        string version = regex.Match(this.FullVersion).Value;
                        return new Version(version);
                    }
                    catch (Exception)
                    {
                        return HSRegistryEntry.NO_VERSION;
                    }
                }
            }
        }

        public string InstallPath { get; internal set; } = String.Empty;
        public string FullVersion { get; internal set; } = String.Empty;
        public DateTime InstallDate { get; internal set; } = MSRegistry.NO_DATE;
        public LocaleType Locale { get; internal set; } = LocaleType.Unknown;
        public bool HasRegistryEntry { get; internal set; } = false;
        public string ExecutingFile { get; set; }
    }
}
