using System.Collections.Generic;
using Valg.EVA.Skanning.Verify.Startup.VerifyBallotPaper.Candidate;

namespace Valg.EVA.Skanning.Verify.Startup.VerifyBallotPaper.VerifiableViewModelsCollection
{
    public class VerificationOrder : IComparer<IViewModelWithVerifiableContent>
    {
        public int Compare(IViewModelWithVerifiableContent x, IViewModelWithVerifiableContent y)
        {
            var compareField = x.VerificationOrder.CompareTo(y.VerificationOrder);
            if (compareField == 0)
            {
                var candidateViewModelX = x as CandidateViewModel;
                var candidateViewModelY = y as CandidateViewModel;
                if (candidateViewModelX != null && candidateViewModelY != null)
                {
                    compareField = candidateViewModelX.CandidateRank.CompareTo(candidateViewModelY.CandidateRank);
                }
            }
            return compareField;
        }
    }
}
