package com.fshark.overseas.advert.processor;

import com.fshark.overseas.advert.modle.SinkMetricEvent;
import com.fshark.overseas.advert.modle.metrics.ActivationMetrics;
import com.fshark.overseas.advert.util.AppConfig;
import com.fshark.overseas.advert.util.Constants;
import com.google.gson.Gson;
import org.apache.flink.api.common.functions.RichFlatMapFunction;
import org.apache.flink.util.Collector;

public class ActivitionMetricToStringProcess extends RichFlatMapFunction<ActivationMetrics, String> {
    public ActivitionMetricToStringProcess(AppConfig appConfig) {
    }

    @Override
    public void flatMap(ActivationMetrics value, Collector<String> out) throws Exception {
        Gson gson = new Gson();
        SinkMetricEvent sinkMetricEvent = new SinkMetricEvent();
        sinkMetricEvent.setEventData(value);
        sinkMetricEvent.setEventType(Constants.TYPE_SINK_EVENT);
        out.collect(gson.toJson(sinkMetricEvent));
    }
}
