// ###################### | #############################################################
// CLASS ................ | SOFTWARE DEVELOPMENT CAPSTONE (C868) ........................
// ASSIGNMENT ........... | C# PERFORMANCE ASSESSMENT ...................................
// TASK ................. | EZP1 TASK 2: SOFTWARE APPLICATION AND DOCUMENTATION .........
// ###################### | #############################################################
// WGU STUDENT .......... | Mark K Ewer .................................................
// STUDENT ID ........... | 001094518 ...................................................
// DEGREE PROGRAM ....... | B.S. in Software Development ................................
// ENROLLED ON .......... | Feb 1, 2019 .................................................
// MENTOR ............... | Becky Stovall ...............................................
// PHONE ................ | (904) 238-7347 ..............................................
// TIME ZONE ............ | Eastern Time ................................................
// EMAIL ................ | MEwer@wgu.edu or Mark@3w3r.com ..............................
// WEB SITE ............. | http://www.markewer.com .....................................
// ###################### | #############################################################
namespace Ewer.Cqrs.Testing
{
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using Ewer.Cqrs.Events;
    using Ewer.Cqrs.Extensions;

    public class CommandProcessingResultWithEvents : CommandProcessingResult, IEnumerable<DomainEvent>
    {
        private readonly List<DomainEvent> _events;

        public CommandProcessingResultWithEvents(IEnumerable<DomainEvent> events)
            : base(events.Any() ? events.Max(e => e.GetGlobalSequenceNumber()) : default(long?))
        {
            _events = events.ToList();
        }

        public IEnumerator<DomainEvent> GetEnumerator()
        {
            return _events.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}
