package com.fshark.overseas.advert.processor.server;

import com.fshark.overseas.advert.modle.metrics.BaseMetrics;
import com.fshark.overseas.advert.modle.metrics.BaseServerMetrics;
import com.fshark.overseas.advert.modle.metrics.ServerActivationMetrics;
import com.fshark.overseas.advert.modle.metrics.ServerRemainMetrics;
import com.fshark.overseas.advert.util.AppConfig;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.util.Collector;

;

/**
 * 留存指标
 */
public class ServerRemainProcessor implements FlatMapFunction<ServerActivationMetrics, ServerRemainMetrics> {

    private AppConfig appConfig;

    public ServerRemainProcessor(AppConfig appConfig) {
        this.appConfig = appConfig;
    }

    @Override
    public void flatMap(ServerActivationMetrics value, Collector<ServerRemainMetrics> out) throws Exception {
        if (value.getDateRemind() == 0L) {
            return;
        }
        ServerRemainMetrics remainMetrics = new ServerRemainMetrics();
        remainMetrics.setData_date(value.getData_date());
        remainMetrics.setData_hour(value.getData_hour());
        copyBaseMetrics(value, remainMetrics);
        remainMetrics.setServer_id(value.getServer_id());
        remainMetrics.setDays(value.getDateRemind() + 1);
        remainMetrics.setUser_num(1L);
        remainMetrics.setMedia_source(value.getMedia_source());
        out.collect(remainMetrics);
    }

    private void copyBaseMetrics(ServerActivationMetrics value, BaseServerMetrics metrics) {
        metrics.setTime_zone(value.getTime_zone());
        metrics.setPlatform(value.getPlatform());
        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());
    }
}
