package cn.stylefeng.team.view.api.format;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.rule.format.BaseSimpleFieldFormatProcess;
import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict;
import com.alibaba.fastjson.JSON;

import java.util.List;
import java.util.stream.Collectors;

public class FormListProcess extends BaseSimpleFieldFormatProcess {

    @Override
    public Class<?> getItemClass() {
        return String.class;
    }

    @Override
    public Object simpleItemFormat(Object businessId) {

        if (ObjectUtil.isEmpty(businessId)) {
            return null;
        }

        String arrayObjString = String.valueOf(businessId);

        List<SimpleDict> simpleDictList = JSON.parseArray(arrayObjString, SimpleDict.class);
        if (ObjectUtil.isEmpty(simpleDictList)) {
            return null;
        }

        List<String> nameList = simpleDictList.stream().map(SimpleDict::getName).collect(Collectors.toList());
        return StrUtil.join("，", nameList);
    }


}
