package com.yem.em.utils;

import java.math.BigDecimal;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;

/**
 * @author 夜子
 * @ClassName EmptyUtils
 * @description: 判断为空工具类
 * @date 2023年07月11日
 * @version: 1.0
 */
public class EmptyUtils {
    public static boolean isEmpty(final Object o) {
        if (o instanceof String) {
            return o == null || o.toString().trim().length() == 0;
        }
        if (o instanceof Long) {
            return o == null || (long) o == 0L;
        }
        if (o instanceof BigDecimal) {
            return o == null || ((BigDecimal) o).compareTo(BigDecimal.ZERO) == 0;
        }
        if (o instanceof Object[]) {
            return o == null || ((Object[]) o).length == 0;
        }
        if (o instanceof DynamicObject) {
            final DynamicObject obj = (DynamicObject) o;
            return obj == null || obj.getPkValue() == null || (long) obj.getPkValue() == 0L
                    || obj.getPkValue().toString().equals("0");
        }
        if (o instanceof DynamicObjectCollection) {
            final DynamicObjectCollection coll = (DynamicObjectCollection) o;
            return coll == null || coll.isEmpty();
        }
        return o == null;
    }

    public static boolean isNotEmpty(Object o) {
        return !isEmpty(o);
    }

    public static boolean equals(String a, String b) {
        return a.equals(b);
    }
}
