using AppData;
using Newtonsoft.Json;
using NKC_SDK;
using System;

namespace NKC_WF.WebUserControls
{
    public partial class cmp_devUtils : BaseUserControl
    {
        #region Protected Methods

        protected void lbtResetNest_Click(object sender, EventArgs e)
        {
            DLMan.taBL.resetNesting(-9999);
        }

        protected void lbtResetProd_Click(object sender, EventArgs e)
        {
            DLMan.taBL.resetProdCall();
        }

        protected void lbtResetStackBuild_Click(object sender, EventArgs e)
        {
            DLMan.taSHL.resetPrepared(-9999);
        }

        protected void lbtSaveLastAnsw_Click(object sender, EventArgs e)
        {
            string content = ComLib.lastRestAnsw();

            // deserializzo.
            baseNestAnsw batchProcAnsw = JsonConvert.DeserializeObject<baseNestAnsw>(content);

            // se non nullo...
            if (batchProcAnsw != null)
            {
                if (batchProcAnsw.OrderType == oType.BatchRequest)
                {
                    if (batchProcAnsw.ProcType == 1)
                    {
                        // deserializzo come BatchreqIniziale (stima)
                        nestReplyBatchInitial rispStima = JsonConvert.DeserializeObject<nestReplyBatchInitial>(content);
                        // 2020.01.16 salvo su mongoDb la risposta...
                        ComLib.man.saveEstAnsw(rispStima);
                    }
                    else if (batchProcAnsw.ProcType == 3)
                    {
                        // deserializzo come BatchreqIniziale (stima)
                        nestReplyBatchExtEst rispStima = JsonConvert.DeserializeObject<nestReplyBatchExtEst>(content);
                        // 2020.01.16 salvo su mongoDb la risposta...
                        ComLib.man.saveExtEstAnsw(rispStima);
                    }
                    else
                    {
                        // deserializzo come BatchreqFinale
                        nestReplyBatchFinal rispNest = JsonConvert.DeserializeObject<nestReplyBatchFinal>(content);
                        // 2020.01.16 salvo su mongoDb la risposta...
                        ComLib.man.saveNestAnsw(rispNest);
                    }
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        #endregion Protected Methods
    }
}