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

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.stylefeng.roses.kernel.rule.format.BaseSimpleFieldFormatProcess;
import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict;
import cn.stylefeng.team.form.api.FormModelServiceApi;

public class FormModelFormatProcess extends BaseSimpleFieldFormatProcess {

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

    @Override
    public Object simpleItemFormat(Object businessId) {
        if (ObjectUtil.isEmpty(businessId)) {
            return null;
        }

        FormModelServiceApi formModelServiceApi = SpringUtil.getBean(FormModelServiceApi.class);

        try {
            Long id = Convert.toLong(businessId);
            String name = formModelServiceApi.getFormModelName(Convert.toLong(businessId));

            return new SimpleDict(id, name, null);

        } catch (Exception e) {

            return null;
        }
    }

}
