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

namespace IngameScript
{
    partial class Program
    {
        public enum DoorAction
        {
            Open,
            Close,
        }

        public class BlockActionDoor : BlockAction
        {
            private IMyDoor _door;
            private DoorAction _action;
            private bool _lockDoor;

            public BlockActionDoor(
                IMyDoor door,
                DoorAction action,
                bool lockDoor = true
            )
            {
                _door = door;
                _action = action;
                _lockDoor = lockDoor;
            }

            protected override IEnumerator<bool> onRun()
            {
                switch (_action)
                {
                    case DoorAction.Open:
                        _door.Enabled = true;
                        _door.OpenDoor();
                        while (_door.Status != DoorStatus.Open) yield return true;
                        break;
                    case DoorAction.Close:
                        _door.Enabled = true;
                        _door.CloseDoor();
                        while (_door.Status != DoorStatus.Closed) yield return true;
                        break;
                }
                if (_lockDoor) _door.Enabled = false;
            }
        }
    }
}