package cn.stylefeng.team.form.api.parser;

import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.team.form.api.entity.FormItem;
import cn.stylefeng.team.form.api.parser.base.BaseFormFormat;
import cn.stylefeng.team.form.api.parser.common.FormFormatUtil;

public class FormSelectDictFormat implements BaseFormFormat {

    @Override
    public Object formatProcess(FormItem formItem, Object originValue) {

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


        Boolean itemMultipleChoiceFlag = formItem.getItemMultipleChoiceFlag();
        if (itemMultipleChoiceFlag == null) {
            return null;
        }

        if (!itemMultipleChoiceFlag) {
            return FormFormatUtil.getDictName(formItem, originValue.toString());
        }

        return FormFormatUtil.getSimpleDictListStringReadable(originValue.toString());
    }

}
