using MECF.Framework.UI.Client.RecipeEditorLib.RecipeModel.Params;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MECF.Framework.UI.Client.RecipeEditorLib.RecipeModel
{
    public class NH3_14GasFlow: RecipeGasFlowM1ToM17_NoneSiH4
    {
        protected override void CalVentFlow(RecipeStep currentStep, string chamberName)
        {
            var currentTotalVentFlow = ((DoubleParam)currentStep.FindParamByControlName(NameTotalVentFlow)).Value;
            var currentHClFlow = ((DoubleParam)currentStep.FindParamByControlName(NameHclFlow)).Value;
            var currentC2H4Flow = ((DoubleParam)currentStep.FindParamByControlName(NameCxHxFlow)).Value;
            var m30Flow = ((DoubleParam)currentStep.FindParamByControlName(Mfc30Flow)).Value;
            var v47Value = ((ComboxParam)currentStep.FindParamByControlName(V47Value)).Value;

            var currentTcsFlowMode = (currentStep.FindParamByControlName(NameTcsFlowMode) as ComboxParam)?.Value;
            var currentHClFlowMode = (currentStep.FindParamByControlName(NameHclFlowMode) as ComboxParam)?.Value;
            var currentC2H4FlowMode = (currentStep.FindParamByControlName(NameCxHxFlowMode) as ComboxParam)?.Value;
            
            var tcsFlow = GetTcsFlow(currentStep, chamberName);

            var currentSiSourTotalFlowForPurge = (currentTcsFlowMode != null && currentTcsFlowMode.Equals(FlowModeParam.FlowModeEnum.Run) == false
                                                     ? tcsFlow
                                                     : 0d) +
                                                 (currentHClFlowMode != null && currentHClFlowMode.Equals(FlowModeParam.FlowModeEnum.Run) == false
                                                     ? currentHClFlow
                                                     : 0d);

            var currentCSourTotalFlowForPurge =
                currentC2H4FlowMode != null && currentC2H4FlowMode.Equals(FlowModeParam.FlowModeEnum.Run) == false
                    ? currentC2H4Flow
                    : 0d;

            m30Flow = v47Value.ToString() == "false" ? m30Flow : 0d;

            var currentVentPushFlow = currentTotalVentFlow - currentSiSourTotalFlowForPurge - currentCSourTotalFlowForPurge - m30Flow;

            ((DoubleParam)currentStep.FindParamByControlName(NameVentPushFlow_M17)).Value = Math.Round(currentVentPushFlow, 1);
        }
    }
}
