package cz.senslog.connector.model.converter;

import com.google.gson.JsonObject;
import cz.senslog.connector.model.api.Converter;
import cz.senslog.connector.model.metno.MetnoModel;
import cz.senslog.connector.model.senslog.SensLogModel;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MetnoToSensLogConverter implements Converter<MetnoModel, SensLogModel> {

    @Override
    public SensLogModel convert(MetnoModel model) {
        if (model == null) {
            return null;
        }

        if (model.getPredictions() == null || model.getPredictions().isEmpty()) {
            return new SensLogModel(model.getFrom(), model.getTo(), Collections.emptyList());
        }

        List<SensLogModel.PassingData> data = new ArrayList<>(model.getPredictions().size());
        for (JsonObject prediction : model.getPredictions()) {
            data.add(new SensLogModel.PassingData(prediction.toString()));
        }

        return new SensLogModel(model.getFrom(), model.getTo(), data);
    }
}