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


import com.fshark.overseas.advert.modle.metrics.ServerActivationMetrics;
import org.apache.flink.api.common.functions.AggregateFunction;
import org.apache.flink.api.java.tuple.Tuple4;

public class ServerActivationAggregateFunction implements AggregateFunction<ServerActivationMetrics, Tuple4<Long,Long,Long,Long>, Tuple4<Long,Long,Long,Long>> {

    @Override
    public Tuple4<Long, Long, Long, Long> createAccumulator() {
        Tuple4<Long, Long, Long, Long> objectObjectObjectObjectTuple4 = new Tuple4<>(0L,0L,0L,0L);
        return objectObjectObjectObjectTuple4;
    }

    @Override
    public Tuple4<Long, Long, Long, Long> add(ServerActivationMetrics value, Tuple4<Long, Long, Long, Long> accumulator) {
        return new Tuple4<Long, Long, Long, Long>(accumulator.f0 + value.getData_register(),accumulator.f1 + value.getData_create_role(),accumulator.f2 + value.getData_day_register_create(),accumulator.f3 + value.getData_active_day_dau());
    }

    @Override
    public Tuple4<Long, Long, Long, Long> getResult(Tuple4<Long, Long, Long, Long> accumulator) {
        return accumulator;
    }

    @Override
    public Tuple4<Long, Long, Long, Long> merge(Tuple4<Long, Long, Long, Long> a, Tuple4<Long, Long, Long, Long> b) {
        return new Tuple4<Long, Long, Long, Long>(a.f0 + b.f0,a.f1 + b.f1,a.f2 + b.f2,a.f3 + b.f3);
    }
}
