package com.yem.wm.utils.groupfunc;

import kd.bos.algo.CustomAggFunction;
import kd.bos.algo.DataType;

import java.util.ArrayList;
import java.util.List;

public class GroupConcatByFunction extends CustomAggFunction<List<String>>{

	public GroupConcatByFunction() {
		super("group_concat", DataType.StringType);
	}

	@Override
	public List<String> newAggValue() {
		return new ArrayList<>();
	}

	@Override
	public List<String> addValue(List<String> arg0, Object arg1) {
		if(arg1 != null && !arg0.contains(arg1)) {
			if (arg0.size() == 0) {
				arg0.add((String) arg1);
			}else {
				arg0.add((String) arg1);
			}
			
		}
		return arg0;
	}

	@Override
	public List<String> combineAggValue(List<String> arg0, List<String> arg1) {
		arg0.addAll(arg1);
		return arg0;
	}

	@Override
	public String getResult(List<String> arg0) {
		return String.join("/", arg0);
	}
}
