using MainShell.Recipe.BaseBoard.Model;
using System.Collections.Generic;
using System.Linq;

namespace MainShell.Process
{
    public class PadTransferRow
    {
        public PadTransferRow()
        {
            Pads = new List<Pad>();
            Direction = DieTransferRowDirection.Positive;
        }

        public int RowIndex { get; set; }

        public DieTransferRowDirection Direction { get; set; }

        public List<Pad> Pads { get; set; }

        public int AvailableCount
        {
            get
            {
                return Pads == null ? 0 : Pads.Count(pad => pad != null);
            }
        }

        public IReadOnlyList<Pad> GetOrderedPads()
        {
            if (Pads == null)
            {
                return new List<Pad>();
            }

            IEnumerable<Pad> orderedPads = Direction == DieTransferRowDirection.Positive
                ? Pads.OrderBy(pad => pad.Column)
                : Pads.OrderByDescending(pad => pad.Column);
            return orderedPads.ToList();
        }

        public IReadOnlyList<Pad> GetAvailablePads()
        {
            return GetOrderedPads().Where(pad => pad != null).ToList();
        }
    }
}
