using FSI.Lib;
using System;
using System.Diagnostics;

namespace FSI.BT.Tools.Commands
{
    /// <summary>
    /// Shows the main window.
    /// </summary>
    public class OpenLinkCommand : CommandBase<OpenLinkCommand>
    {
        public override void Execute(object parameter)
        {
            string url = String.Empty;

            switch ((string)parameter)
            {
                case "ZentralWeb":
                    url = Global.Settings.ZentralWebUrl;
                    break;

                case "Schichtbuch":
                    url = Global.Settings.SchichtbuchUrl;
                    break;

                case "SPS":
                    url = Global.Settings.SPSUrl;
                    break;

                case "PL1.Pls":
                    url = Global.Settings.Pl1PlsUrl;
                    break;

                case "PL2.Pls":
                    url = Global.Settings.Pl2PlsUrl;
                    break;

                case "PL2.Als":
                    url = Global.Settings.Pl2Als;
                    break;

                case "PL3.Pls":
                    url = Global.Settings.Pl3PlsUrl;
                    break;

                case "FSI.Gitea":
                    url = Global.Settings.GiteaUrl;
                    break;

                case "FSI.Wiki":
                    url = Global.Settings.WikiUrl;
                    break;
                
                case "Erp":
                    url = Global.Settings.ErpUrl;
                    break;
            }

            if (url == String.Empty)
                return;

            url = url.Replace("&", "^&");
            Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
        }

        public override bool CanExecute(object parameter)
        {
            string url = String.Empty;
            switch ((string)parameter)
            {
                case "FSI.Gitea":
                    return Global.AdminRights;

                case "FSI.Wiki":
                    return Global.AdminRights;

                default:
                    return true;
            }         
        }
    }
}