using C4IT.F4SD.SupportCaseProtocoll.Models;
using C4IT.FASD.Base;
using C4IT.MultiLanguage;

namespace FasdDesktopUi.Basics.Services.ProtocollService
{
    internal static class QuickTipStepProtocollEntryOutput
    {
        public static QuickTipStepProtocollEntry GetQuickTipStepProtocollEntry(cQuickTipElement quickTipElementDefinition, bool wasSuccessfull)
        {
            string ascii = GetAsciiOutput(quickTipElementDefinition, wasSuccessfull);
            string html = GetHtmlOutput(quickTipElementDefinition, wasSuccessfull);
            return new QuickTipStepProtocollEntry(ascii, html)
            {
                Name = quickTipElementDefinition.Name,
                WasSuccessfull = wasSuccessfull
            };
        }

        private static string GetAsciiOutput(cQuickTipElement quickTipElementDefinition, bool wasSuccessfull)
        {
            string currentLanguage = cMultiLanguageSupport.CurrentLanguage;
            try
            {
                cMultiLanguageSupport.CurrentLanguage = cF4SDCockpitXmlConfig.Instance.HealthCardConfig.ProtocollLanguage ?? currentLanguage;
                string ascii = wasSuccessfull ? cMultiLanguageSupport.GetItem("QuickTips.Copy.ManualStep.Successfull") : cMultiLanguageSupport.GetItem("QuickTips.Copy.ManualStep.Unsuccessfull");
                return string.Format(ascii, quickTipElementDefinition?.Names?.GetValue());
            }
            finally
            {
                cMultiLanguageSupport.CurrentLanguage = currentLanguage;
            }
        }

        private static string GetHtmlOutput(cQuickTipElement quickTipElementDefinition, bool wasSuccessfull)
            => GetAsciiOutput(quickTipElementDefinition, wasSuccessfull);
    }
}
