using FeMM.Common.Models;
using FeMM.Grasshopper.DataTypes.FeMM;
using FeMM.Grasshopper.Helpers;
using Grasshopper.Kernel;
using System;
using System.Collections.Generic;

namespace FeMM.Grasshopper.Components.Definitions
{
    public class LoadCaseConstructionStagePhaseComponent : GH_Component
    {
        /// <summary>
        /// Initializes a new instance of the LoadCaseComponent class.
        /// </summary>
        public LoadCaseConstructionStagePhaseComponent()
          : base("Construction Stage", "CS", "A Construction Stage definition", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_DEFINITIONS)
        {
        }

        /// <summary>
        /// Registers all the input parameters for this component.
        /// </summary>
        protected override void RegisterInputParams(GH_InputParamManager pManager)
        {
            pManager.AddGenericParameter("Operations", "Os", "Operations of a stage", GH_ParamAccess.list);
            pManager.AddIntegerParameter("Duration", "D", "Duration in days of the stage", GH_ParamAccess.item, 0);
            pManager.AddBooleanParameter("SaveOutput", "SO", "If true, analysis output is saved for the stage", GH_ParamAccess.item, true);
            pManager.AddTextParameter("Output Name", "ON", "User-specified output name for the stage", GH_ParamAccess.item, "");
        }

        /// <summary>
        /// Registers all the output parameters for this component.
        /// </summary>
        protected override void RegisterOutputParams(GH_OutputParamManager pManager)
        {
            pManager.AddGenericParameter("Construction Stage Phase", "CSP", "The defined Construction Stage Phase", GH_ParamAccess.item);
        }

        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var operations = new List<GH_StageConstructionOperation>();
            int duration = 0;
            bool save = false;
            string prefix = "";

            if (!DA.GetDataList(0, operations))
                return;
            DA.GetData(1, ref duration);
            DA.GetData(2, ref save);
            DA.GetData(3, ref prefix);

            var stage = new StageConstructionLoadCaseModel.ConstructionStage()
            {
                Duration = duration,
                OutputSaved = save,
                OutputPrefix = prefix,
            };

            foreach (GH_StageConstructionOperation op in operations)
                stage.Operations.Add(new StageConstructionLoadCaseModel.ConstructionStage.OperationModel(op.Value));

            DA.SetData(0, new GH_ConstructionStage(stage));
        }

        public override GH_Exposure Exposure => GH_Exposure.quarternary;

        /// <summary>
        /// Provides an Icon for the component.
        /// </summary>
        protected override System.Drawing.Bitmap Icon => Properties.Resources.StagedConstructionPhaseIcon;

        /// <summary>
        /// Gets the unique ID for this component. Do not change this ID after release.
        /// </summary>
        public override Guid ComponentGuid => new("A585ECB5-F868-4971-91BC-CCB5BBBF48DD");
    }
}
303 files24 directories