package com.fshark.overseas.advert.processor;


import com.fshark.overseas.advert.modle.AppsFlyerEvent;
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 org.apache.flink.api.common.functions.RichFlatMapFunction;
import org.apache.flink.util.Collector;

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

    @Override
    public void flatMap(ActivationMetrics value, Collector<RemainMetrics> out) throws Exception {
        if (value.getDateRemind() == 0L) {
            return;
        }
        RemainMetrics remainMetrics = new RemainMetrics();
        copyBaseMetrics(value, remainMetrics);
        remainMetrics.setDays(value.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());
    }
}
