// Created with MonoDevelop
//
//    QuickStep: Acquire, view and identify spectra 
//    Copyright (C) 2021 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 Hiperscan.Common.I18n;

namespace Hiperscan.Extensions.ApoIdentSoftwareUpgrade
{
    public class LinkManager
    {
        public LinkManager(Locale.LocaleType locale, SoftwareTestEnvironment test_enviroment)
        {
            this.Test = test_enviroment;
            this.CurrentLocale = locale;
            this.InitLinks();
        }

        public string GetLink(ProjectType project)
        {
            string link = String.Empty;

            //if (project != ProjectType.Invalid)
            {
                if (this.Test.IsActive)
                {
                    link = this.Test.GetTestLink(project);
                }
                else
                {
                    switch (project)
                    {
                        case ProjectType.QuickStep:
                            link = this.QuickStepLinks[this.CurrentLocale];
                            break;

                        case ProjectType.IdentModule:
                            link = this.IdentModuleLinks[this.CurrentLocale];
                            break;

                        default:
                            break;
                    }
                }
            }

            Console.WriteLine("Link manager: {0} -> {1}: {2}",
                              project,
                              this.CurrentLocale,
                              link);
            return link;
        }

        private void InitLinks()
        {
            this.IdentModuleLinks = new Dictionary<Locale.LocaleType, string>();
            this.QuickStepLinks = new Dictionary<Locale.LocaleType, string>();
            foreach (Locale.LocaleType locale in Enum.GetValues(typeof(Locale.LocaleType)))
            {
                if (locale == Locale.LocaleType.Unknown)
                    continue;

                this.QuickStepLinks.Add(locale, "NO_LINK");
                this.IdentModuleLinks.Add(locale, "NO_LINK");
            }

            this.QuickStepLinks[Locale.LocaleType.de_DE] = "http://hiperscan-download.n2g31.com/uwzoqy1j-8b1we807-tlw3qir6-15w0";
            this.IdentModuleLinks[Locale.LocaleType.de_DE] = "http://hiperscan-download.n2g31.com/uwzoqy1j-8b1we807-xfqj1eva-h86";
        }

        private Dictionary<Locale.LocaleType, string> QuickStepLinks { get; set; }
        private Dictionary<Locale.LocaleType, string> IdentModuleLinks { get; set; }

        private Locale.LocaleType CurrentLocale { get; set; }
        private SoftwareTestEnvironment Test { get; set; }
    }
}
