package nckd.jxccl.sit.hcsi.common.constant.enums;

import kd.bos.dataentity.metadata.IDataEntityProperty;
import kd.bos.entity.property.*;
import nckd.jxccl.sit.hcsi.common.constant.model.SITI18NParam;

import java.math.BigDecimal;
import java.util.Date;

public enum DataTypeEnum {

    NUMBERIC(1010L, new SITI18NParam("数值", "DataTypeEnum_0", "swc-hsbp-common")),
    AMOUNT(1020L, new SITI18NParam("金额", "DataTypeEnum_1", "swc-hsbp-common")),
    STRING(1030L, new SITI18NParam("文本", "DataTypeEnum_2", "swc-hsbp-common")),
    INTEGER(1040L, new SITI18NParam("整型", "DataTypeEnum_3", "swc-hsbp-common")),
    BOOLEAN(1060L, new SITI18NParam("逻辑", "DataTypeEnum_4", "swc-hsbp-common")),
    DATE(1050L, new SITI18NParam("日期", "DataTypeEnum_5", "swc-hsbp-common")),
    LONG(1080L, new SITI18NParam("长整型", "DataTypeEnum_7", "swc-hsbp-common")),
    NULL(0L, new SITI18NParam("空", "DataTypeEnum_6", "swc-hsbp-common"));

    private final long dbId;
    private SITI18NParam name;

    private DataTypeEnum(long dbId, SITI18NParam name) {
        this.dbId = dbId;
        this.name = name;
    }

    public static DataTypeEnum getDataType(String name) {
        DataTypeEnum dataType = null;
        if (!"string".equalsIgnoreCase(name) && !"text".equalsIgnoreCase(name) && !"boolean".equalsIgnoreCase(name) && !"enum".equalsIgnoreCase(name)) {
            if (!"decimal".equalsIgnoreCase(name) && !"amount".equalsIgnoreCase(name) && !"numberic".equalsIgnoreCase(name) && !"bigdecimal".equalsIgnoreCase(name) && !"num".equalsIgnoreCase(name)) {
                if ("date".equalsIgnoreCase(name)) {
                    dataType = DATE;
                } else if (!"null".equalsIgnoreCase(name) && !"void".equalsIgnoreCase(name)) {
                    if ("long".equalsIgnoreCase(name)) {
                        dataType = LONG;
                    } else if ("int".equalsIgnoreCase(name)) {
                        dataType = INTEGER;
                    }
                } else {
                    dataType = NULL;
                }
            } else {
                dataType = NUMBERIC;
            }
        } else {
            dataType = STRING;
        }

        return dataType;
    }

    public static DataTypeEnum getDataType(Class<?> clazz) {
        if (String.class.isAssignableFrom(clazz)) {
            return STRING;
        } else if (BigDecimal.class.isAssignableFrom(clazz)) {
            return NUMBERIC;
        } else if (Date.class.isAssignableFrom(clazz)) {
            return DATE;
        } else {
            return Boolean.class.isAssignableFrom(clazz) ? BOOLEAN : NULL;
        }
    }

    public static DataTypeEnum getDataType(IDataEntityProperty property) {
        if (!(property instanceof TextProp) && !(property instanceof ComboProp)) {
            if (property instanceof AmountProp) {
                return AMOUNT;
            } else if (!(property instanceof DateProp) && !(property instanceof DateTimeProp)) {
                if (property instanceof DecimalProp) {
                    return NUMBERIC;
                } else if (property instanceof IntegerProp) {
                    return INTEGER;
                } else {
                    return property instanceof BooleanProp ? BOOLEAN : NULL;
                }
            } else {
                return DATE;
            }
        } else {
            return STRING;
        }
    }

    public static DataTypeEnum getDataTypeById(long dbId) {
        DataTypeEnum[] var2 = values();
        int var3 = var2.length;

        for(int var4 = 0; var4 < var3; ++var4) {
            DataTypeEnum dataType = var2[var4];
            if (dataType.getDbId() == dbId) {
                return dataType;
            }
        }

        return NULL;
    }

    public static String getNameByDbId(long dbId) {
        DataTypeEnum[] var2 = values();
        int var3 = var2.length;

        for(int var4 = 0; var4 < var3; ++var4) {
            DataTypeEnum dataType = var2[var4];
            if (dataType.getDbId() == dbId) {
                return dataType.getName();
            }
        }

        return NULL.getName();
    }

    public long getDbId() {
        return this.dbId;
    }

    public String getName() {
        return this.name.loadKDString();
    }
}
