package com.fshark.overseas.advert.processor;


import com.fshark.overseas.advert.modle.AppsFlyerEvent;
import com.fshark.overseas.advert.modle.SinkMetricEvent;
import com.fshark.overseas.advert.modle.metrics.ActivationMetrics;
import com.fshark.overseas.advert.modle.metrics.BaseMetrics;
import com.fshark.overseas.advert.modle.metrics.RemainMetrics;
import com.fshark.overseas.advert.util.Constants;
import org.apache.flink.api.common.functions.RichFlatMapFunction;
import org.apache.flink.util.Collector;

/**
 * 留存指标
 */
public class RemainProcess extends RichFlatMapFunction<SinkMetricEvent, RemainMetrics> {

    @Override
    public void flatMap(SinkMetricEvent value, Collector<RemainMetrics> out) throws Exception {
        if (Constants.TYPE_SINK_METRIC.equals(value.getEventType())) {
            ActivationMetrics eventData = value.getEventData();
            if (eventData.getDateRemind() == 0L) {
                return;
            }
            RemainMetrics remainMetrics = new RemainMetrics();
            copyBaseMetrics(eventData, remainMetrics);
            remainMetrics.setDays(eventData.getDateRemind());
            remainMetrics.setUser_num(1L);
            out.collect(remainMetrics);
        }

    }

    private void copyBaseMetrics(ActivationMetrics value, BaseMetrics metrics) {
        metrics.setData_date(value.getData_date());
        metrics.setData_hour(value.getData_hour());
        metrics.setTime_zone(value.getTime_zone());
        metrics.setPlatform(value.getPlatform());
        metrics.setMedia_source(value.getMedia_source());
        metrics.setGame_id(value.getGame_id());
        metrics.setCampaign_id(value.getCampaign_id());
        metrics.setAd_set_id(value.getAd_set_id());
        metrics.setAd_id(value.getAd_id());
        metrics.setRegion(value.getRegion());
        metrics.setData_type(value.getData_type());
        metrics.setChannel(value.getChannel());
    }
}
