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.configuration.Configuration;
import org.apache.flink.util.Collector;

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

    private  Gson gson;
    @Override
    public void open(Configuration parameters) throws Exception {
        super.open(parameters);
        gson = new Gson();
    }

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