using Valg.EVA.Skanning.Entity.ReadModel;
using Valg.EVA.Skanning.Entity.SerializedEntities.FieldValueModel;
using Valg.EVA.Skanning.Entity.WriteModel;
using Newtonsoft.Json;
using Valg.EVA.Skanning.ServicesModel.ServiceContracts.Scan.Write;

namespace Valg.EVA.Skanning.ServicesModel.Internal.Serializers
{
    public static class WriteInDataJsonSerializer
    {
        public static WriteInData Deserialize(BallotPaperFieldValue ballotPaperFieldValue)
        {
            string json = ballotPaperFieldValue.Value;
            return JsonConvert.DeserializeObject<WriteInData>(json);
        }

        public static WriteInData Deserialize(BallotPaperFieldValueInsert ballotPaperField)
        {
            string json = ballotPaperField.Value;
            return JsonConvert.DeserializeObject<WriteInData>(json);
        }

        public static void SerializeWriteInDataToJson(this BallotPaperFieldValue ballotPaperFieldValue, WriteInData writeInData)
        {
            ballotPaperFieldValue.Value = JsonConvert.SerializeObject(writeInData);
        }

        public static void SerializeWriteInDataToJson(this ScannedField scannedField, WriteInData writeInData)
        {
            scannedField.Value = JsonConvert.SerializeObject(writeInData);
        }
    }
}
