using Valg.EVA.Skanning.Entity.ReadModel;
using Valg.EVA.Skanning.ServicesModel.Internal.BallotNumber;

namespace Valg.EVA.Skanning.ServicesModel.Internal.Interpreter
{
    public static class BallotNumberAndBarcodeConsistencyChecker
    {
        public static bool IsBallotNumberConsistentWithBarcodeIncludingContest(this BallotPaperFieldValue ballotNumberField, string barcodeLong)
        {
            return ballotNumberField.IsBallotNumberConsistentWithBarcodeExcludingContest(barcodeLong)
                   && ballotNumberField.Value.ContestId() == barcodeLong.GetContestIdFromBarcodeLong();
        }

        public static bool IsBallotNumberConsistentWithBarcodeExcludingContest(this BallotPaperFieldValue ballotNumberField, string barcodeLong)
        {
            string ballotNumber = ballotNumberField.Value;
            return ballotNumber.ElectionEventId() == barcodeLong.GetElectionEventIdFromBarcodeLong()
                   && ballotNumber.ElectionGroupId() == barcodeLong.GetElectionGroupIdFromBarcodeLong()
                   && ballotNumber.ElectionId() == barcodeLong.GetElectionIdFromBarcodeLong();
        }
    }
}
