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

namespace IngameScript
{
    public class Door
    {
        public Door()
        {
            Hinges = new List<DoorHinge>();
        }

        // Add a hinge to the door
        public void AddHinge(IMyMotorStator hinge)
        {
            Hinges.Add(new DoorHinge(hinge));
        }

        public void OpenDoor()
        {
            foreach (DoorHinge hinge in Hinges)
            {
                hinge.OpenDoorHinge();
            }
        }

        public void CloseDoor()
        {
            foreach (DoorHinge hinge in Hinges)
            {
                hinge.CloseDoorHinge();
            }
        }

        // Process the door's movement. This will return true when the door is done moving.
        public bool Actuate()
        {
            bool done = true;
            foreach (DoorHinge hinge in Hinges)
            {
                if (!hinge.Actuate()) done = false;
            }
            return done;
        }

        public bool Locked()
        {
            foreach (DoorHinge hinge in Hinges)
            {
                if (!hinge.Locked()) return false;
            }
            return true;
        }

        private List<DoorHinge> Hinges;
    }
}