using System.Collections.Generic;
using Valg.EVA.Skanning.Entity.ReadModel;

namespace Valg.EVA.Skanning.ServicesModel.Internal.Verification
{
    public class ScanAndInterpretFieldValueMergeComparer : IEqualityComparer<BallotPaperFieldValue>
    {
        public bool Equals(BallotPaperFieldValue x, BallotPaperFieldValue y)
        {
            var isFieldTypeEquivalent = x.FieldType == y.FieldType;

            if (isFieldTypeEquivalent && x.FieldIndex.HasValue && y.FieldIndex.HasValue)
            {
                return x.FieldIndex.Value == y.FieldIndex.Value;
            }

            return isFieldTypeEquivalent;
        }

        public int GetHashCode(BallotPaperFieldValue obj)
        {
            return obj.FieldType.GetHashCode();
        }
    }
}
