package com.alterdekim.game.xml;

import com.alterdekim.game.component.game.avatar.BodyPartType;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

public class LayerIdSerializer extends JsonSerializer<Object> {
    @Override
    public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeNumber(LayerIdSerializer.parse(o));
    }

    public static Integer parse(Object o) {
        return o instanceof String ? (BodyPartType.valueOf((String) o)).getLayerId() : ((Number) o).intValue();
    }
}
