using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PXP.Crawler.API.Model;

namespace PXP.Crawler.API.Plugins.Values.Strings
{
    [NodeInfo("String Split", typeof(StringSplitNode), Category = "Values.Strings")]
    public class StringSplitNode : Node
    {
        private string[] values = new string[] { "" };
        private string cvalue = "";
        private string by = ";";

        public StringSplitNode(Program program) : base(program)
        {
        }

        private void Update()
        {
            if (by.Length > 0 && cvalue.Length > 0)
            {
                values = cvalue.Split(by.ToCharArray());
                NotifyPropertyChange("Values");                
            }
            else
            {
                values = new string[] { cvalue };
            }
        }


        [NodePropertyPin(NodePinDirection.Input)]
        public string Value
        {
            get
            {
                return cvalue;
            }
            set
            {
                this.cvalue = value;
                Update();
            }
        }

        [NodePropertyPin(NodePinDirection.Input)]
        public string By
        {
            get
            {
                return by;
            }
            set
            {
                by = value;
                Update();
            }
        }

        [NodePropertyPin(NodePinDirection.Output)]
        public string[] Values
        {
            get
            {
                return values;
            }
        }
    }
}
