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" +
              "Replace", typeof(StringReplaceNode), Category = "Values.Strings")]
    public class StringReplaceNode : Node
    {
        private string source = "";
        private string search = "";
        private string replace = "";
        private string result = "";

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

        private void Update()
        {
            result = source.Replace(search, replace);
            NotifyPropertyChange("Result");
        }


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

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

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

        [NodePropertyPin(NodePinDirection.Output)]
        public string Result
        {
            get
            {
                return result;
            }
        }
    }
}
