using System.ComponentModel.DataAnnotations;
using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
namespace FileFlows.BasicNodes.Conditions;
///
/// Base class for the If flow elements
///
public abstract class IfBase : Node
{
///
/// Gets or sets the number of inputs
///
public override int Inputs => 1;
///
/// Gets or sets the number of outputs
///
public override int Outputs => 2;
///
/// Gets or sets the flow element type
///
public override FlowElementType Type => FlowElementType.Logic;
///
/// Gets or sets the icon
///
public override string Icon => "fas fa-question";
///
/// Gets or sets the variable name
///
[Text(1)]
[Required]
public string Variable { get; set; }
///
/// Test the variable value matches
///
/// the node parameters
/// the variable value
/// the output to call next
protected abstract int DoCheck(NodeParameters args, object value);
///
/// Executes the flow element
///
/// the node parameters
/// the output node
public override int Execute(NodeParameters args)
{
if (string.IsNullOrWhiteSpace(Variable))
{
args.Logger?.WLog("Variable not set");
return 2;
}
var value = args.GetVariable(Variable);
if (value == null)
{
args.Logger?.WLog($"Variable '{Variable}' was null.");
return 2;
}
return DoCheck(args, value);
}
}