package com.eactive.eai.rms.common.converter;

import com.eactive.eai.rms.onl.transaction.apim.ui.ApiInterfaceUI;
import com.eactive.eai.rms.onl.transaction.apim.ui.ApiSpecInfoUI;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class StringToListApiSpecUIConverter implements Converter<String, List<ApiSpecInfoUI>> {

    private final ObjectMapper objectMapper;

    @Override
    public List<ApiSpecInfoUI> convert(String source) {
        try {
            return objectMapper.readValue(source, new TypeReference<List<ApiSpecInfoUI>>() {
            });
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }

}
