using AddinExamplesGeneral;
using System;
using System.Collections.Generic;
using Toolbox.Docking.Api.Control;
using Toolbox.Docking.Api.ExtraActions;
using Toolbox.Docking.Api.Objects;
using Toolbox.Docking.Api.Objects.Calculator;
using Toolbox.Docking.Api.Units;

namespace ToolboxAddinExamples.Calculator
{
    public class TbCalculatorAddinFactory : ITbCalculatorFactory,ITbObjectFactoryTunable, ITbObjectFactoryExplain, ITbObjectFactoryExtraAction
    {
        private const string Caption = "(Test) Characters count";
        private const string Description = "Dummy Calculator - Toolbox Docking Example";
        private const string Donator = "LMC";
        private const string Disclaimer = "For demonstrational purposes only.";
        private const string Authors = "Toolbox Development Team @LMC";
        private const string Url = "http://toolbox.oasis-lmc.org";
        private static readonly Guid Guid = new Guid("09D250D6-4AC6-40B7-8E17-C01AB5F2D064");
        private static readonly Version Version = new Version(1, 0);
        private static readonly Guid ScaleGuid = new Guid("0046D76D-BE99-45DF-9D9F-63747912CEC8");

        public TbCalculatorAddinFactory()
        {
            ObjectId = new TbObjectId(Caption, Guid, Version);
            ObjectAbout = new TbObjectAbout(Description, Donator, Disclaimer, Authors, Url, Caption,
            null, null);
            Flags = TbObjectFlags.None;
            CalculatorFlags = CalculatorFlags.None;
            ScaleDeclaration = new TbRatioScale(CalculatorAddin.ScaleName, CalculatorAddin.ScaleName, ScaleGuid, CalculatorAddin.UnitName);
        }

        public bool InitFactory(IList<string> errorLog, ITbInitTask initTask)
        {
            return true;
        }

        public TbObjectFlags Flags { get; }

        public TbObjectId ObjectId { get; }

        public TbObjectAbout ObjectAbout { get; }

        public ITbCalculator GetCalculator(ITbWorkTask task)
        {
            return new CalculatorAddin();
        }

        public TbScale ScaleDeclaration { get; }
        
        public CalculatorFlags CalculatorFlags { get; }

       public string ClientOptionsModule => AddinExamplesConsts.CalculatorOptions;

        public string DefaultOptions => "Example options. This must be serialized real options";
        public IReadOnlyList<string> FormatOptions(string options)
        {
            var list = new List<string> {"Example formatted options", "This is a dummy calculator"};
            return list;
        }

        public string ClientExplainModule => AddinExamplesConsts.CalculatorExplainer;

             public IEnumerable<TbExtraActionDefinition> GetExtraActions()
        {
            yield return new TbExtraActionDefinition("Direct client action", CalculatorAddin.DirectClientEa, TbExtraActionTarget.Chemical, AddinExamplesConsts.CalculatorDirectClientExtraAction);
            yield return new TbExtraActionDefinition("Server call action <noExplain>", CalculatorAddin.ServerEaNoExplain, TbExtraActionTarget.Chemical, string.Empty);
            yield return new TbExtraActionDefinition("Server call action <explain>", CalculatorAddin.ServerEaExplain, TbExtraActionTarget.Chemical, string.Empty);
        }

        
   
    }
}