using Serein.Library.Api;
using Serein.NodeFlow.Model;
using Serein.NodeFlow.Model.Nodes;
using Serein.Workbench.Node.ViewModel;

namespace Serein.Workbench.Node.View
{
    /// <summary>
    /// ExprOpNodeControl.xaml 的交互逻辑
    /// </summary>
    public partial class ExpOpNodeControl : NodeControlBase, INodeJunction
    {
        /// <summary>
        /// 表达式操作节点控件
        /// </summary>
        public ExpOpNodeControl() : base()
        {
            // 窗体初始化需要
            var env = App.GetService<IFlowEnvironment>();
            ViewModel = new ExpOpNodeControlViewModel(new SingleExpOpNode(env));
            base.ViewModel.IsEnabledOnView = false;
            base.ViewModel.NodeModel.DisplayName = "[表达式]";
            DataContext = ViewModel;
            InitializeComponent();
        }

        /// <summary>
        /// 表达式操作节点控件构造函数，使用指定的 ViewModel 初始化
        /// </summary>
        /// <param name="viewModel"></param>
        public ExpOpNodeControl(ExpOpNodeControlViewModel viewModel) :base(viewModel)
        {
            DataContext = viewModel;
            viewModel.NodeModel.DisplayName = "[表达式]";
            InitializeComponent();
        }

        /// <summary>
        /// 入参控制点（可能有，可能没）
        /// </summary>
        JunctionControlBase INodeJunction.ExecuteJunction => this.ExecuteJunctionControl;

        /// <summary>
        /// 下一个调用方法控制点（可能有，可能没）
        /// </summary>
        JunctionControlBase INodeJunction.NextStepJunction => this.NextStepJunctionControl;

        /// <summary>
        /// 返回值控制点（可能有，可能没）
        /// </summary>
        JunctionControlBase INodeJunction.ReturnDataJunction => this.ResultJunctionControl;

        /// <summary>
        /// 方法入参控制点（可能有，可能没）
        /// </summary>
        private JunctionControlBase[] argDataJunction;

        /// <summary>
        /// 方法入参控制点（可能有，可能没）
        /// </summary>
        JunctionControlBase[] INodeJunction.ArgDataJunction
        {
            get
            {
                argDataJunction = new JunctionControlBase[1];
                argDataJunction[0] = this.ArgJunctionControl;
                return argDataJunction;
            }
        }
    }
}
