using Valg.EVA.Skanning.Entity.SqlConnection;
using Valg.EVA.Skanning.Entity.WriteModel;
using Newtonsoft.Json;

namespace Valg.EVA.Skanning.Repositories.CountingResult
{
    public class CountingResultWritableRepository : ICountingResultWritableRepository
    {
        private readonly ISqlConnectionFactory connectionFactory;

        public CountingResultWritableRepository(ISqlConnectionFactory connectionFactory)
        {
            this.connectionFactory = connectionFactory;
        }
        
        public void InsertCountingResult(CountingResultInsert countingResultInsert)
        {
            connectionFactory.SP_ExecuteVoid("CountingResult_InsertCountingResult", new
            {
                CountingId = countingResultInsert.CountingId,
                BallotPaperId = countingResultInsert.BallotPaperId,
                VoteInformation = JsonConvert.SerializeObject(countingResultInsert.CastVote)
            });
        }
    }
}
