using System;
using System.Collections.Generic;

using Grasshopper.Kernel;
using Rhino.Geometry;

namespace Workshop
{
    public class GhcMovingParticle : GH_Component
    {
        Point3d currentPosition = new Point3d(0, 0, 0);


        public GhcMovingParticle()
            : base("Moving Particle", "Moving Particle",
                "Moving Particle",
                "Workshop", "Utilities")
        {
        }


        protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
        {
            pManager.AddBooleanParameter("Reset", "Reset", "Reset", GH_ParamAccess.item);
            pManager.AddVectorParameter("Velocity", "Velocity", "Velocity", GH_ParamAccess.item);
            pManager.AddBooleanParameter("Play", "Play", "Play", GH_ParamAccess.item);
        }


        protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
        {
            pManager.AddPointParameter("Particle", "Particle", "Particle", GH_ParamAccess.item);
        }


        protected override void SolveInstance(IGH_DataAccess DA)
        {
            bool iReset = true;
            DA.GetData(0, ref iReset);

            Vector3d iVelocity = new Vector3d();
            DA.GetData(1, ref iVelocity);

            bool iPlay = true;
            DA.GetData(2, ref iPlay);

            if (iReset)
            {
                currentPosition = new Point3d(0, 0, 0);
                return;
            }

            currentPosition += iVelocity;

            DA.SetData(0, currentPosition);

            if (iPlay)
                ExpireSolution(true);

        }


        protected override System.Drawing.Bitmap Icon
        {
            get
            {
                return null;
            }
        }


        public override Guid ComponentGuid
        {
            get { return new Guid("{2835d70d-92cf-457d-994d-e055177437d1}"); }
        }
    }
}