using EVCB_OCPP.WEBAPI.Models.WebAPI.Dto;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;

namespace EVCB_OCPP.WEBAPI.Helpers
{
    public class ConnectorTypeConverter : JsonConverter
    {
        public override bool CanConvert(Type objectType)
        {
            return objectType == typeof(string);
        }

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var enumString = (string)reader.Value;

            return Enum.Parse(typeof(ConnectorType), enumString, true);
        }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            ConnectorType messageTransportResponseStatus = (ConnectorType)value;

            string result = messageTransportResponseStatus.ToString();
            result=  result.Replace('_', ' ');

            writer.WriteValue(result);
        }
    }
}