using System.Collections.Generic;
using Sandbox.ModAPI.Ingame;
using SpaceEngineers.Game.ModAPI.Ingame;

namespace IngameScript
{
    partial class Program
    {
        public enum MergeAction
        {
            Merge,
            Unmerge,
        }

        public class BlockActionMerge : BlockAction
        {
            private IMyShipMergeBlock _connector;
            private MergeAction _action;

            public BlockActionMerge(
                IMyShipMergeBlock connector,
                MergeAction action
            )
            {
                _connector = connector;
                _action = action;
            }

            protected override IEnumerator<bool> onRun()
            {
                switch (_action)
                {
                    case MergeAction.Merge:
                        _connector.Enabled = true;
                        while (!_connector.IsConnected) yield return true;
                        break;
                    case MergeAction.Unmerge:
                        _connector.Enabled = false;
                        while (_connector.IsConnected) yield return true;
                        break;
                }
            }
        }
    }
}