using System;
using System.Collections.Generic;

using Grasshopper.Kernel;
using Rhino.Geometry;

namespace Workshop
{
    public class GhcAverage : GH_Component
    {
        public GhcAverage()
            : base("Average of two numbers", "Average",
                "Compute the average of two numbers",
                "Workshop", "Utilities")
        {
        }


        protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
        {
            pManager.AddNumberParameter("First number", "First", "The first number", GH_ParamAccess.item);
            pManager.AddNumberParameter("Second number", "Second", "The second number", GH_ParamAccess.item);
        }


        protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
        {
            pManager.AddNumberParameter("Result", "Result", "The average value", GH_ParamAccess.item);
        }


        protected override void SolveInstance(IGH_DataAccess DA)
        {
            double a = 0.0;
            double b = 0.0;

            bool success1 = DA.GetData(0, ref a);
            bool success2 = DA.GetData(1, ref b);

            if (success1 && success2)
            {
                double result = 0.5 * (a + b);
                DA.SetData(0, result);
            }
            else
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Please check input");
            }

        }


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


        public override Guid ComponentGuid
        {
            get { return new Guid("{dbbde2ed-5fd6-4d9f-bfe5-98550c49083a}"); }
        }
    }
}