package cn.axzo.workflow.common.model.response.form.instance;

import cn.axzo.workflow.common.enums.FormFieldTypeEnum;
import io.swagger.annotations.ApiModel;
import lombok.Data;

import java.util.Map;
import java.util.Objects;

/**
 * 表单实例数据的响应模型
 *
 * @author wangli
 * @since 2025-08-04 10:54
 */
@ApiModel("表单实例数据的响应模型")
@Data
public class FormDataVO {
    private String fieldId;

    private Object fieldValue;

    private FormFieldTypeEnum fieldType;

    /**
     * 数字表单组件的格式化值：数字+单位
     *
     * @return
     */
    public Object getFormatDecimalValue() {
        switch (fieldType) {
            case decimal:
                Map<String, Object> decimalMap = (Map<String, Object>) fieldValue;
                Object value = decimalMap.getOrDefault("value", "");
                if (Objects.isNull(value)) {
                    return "";
                } else {
                    return value + "" + decimalMap.getOrDefault("unit", "");
                }
            default:
                return fieldValue;
        }
    }
}
