package thyyxxk.webserver.utils;

import cn.hutool.core.collection.CollUtil;
import thyyxxk.webserver.config.exception.BizException;
import thyyxxk.webserver.config.exception.ExceptionEnum;

import java.util.Collection;
import java.util.Map;

/**
 * @Description:断言工具类
 * @Author:lihong
 * @Date: 2022/12/13
 */
public class AssertUtil {

    /**
     * @description: 不能为空  支持集合 ,字符串 ,Map
     * @author: lihong
     * @date: 2022/12/13 9:23
     * @param: object
     * @param: message
     **/
    public static void isnotBlank(Object object,String message){
        if (object == null) {
            throw new BizException(ExceptionEnum.LOGICAL_ERROR, message);
        }
       else if (object instanceof Collection) {
            if(CollUtil.isEmpty((Collection)object)){
                throw new BizException(ExceptionEnum.LOGICAL_ERROR, message);
            }
        }
        else if (object instanceof Map) {
            if(CollUtil.isEmpty((Map)object)){
                throw new BizException(ExceptionEnum.LOGICAL_ERROR, message);
            }
        }else {
            if (StringUtil.isBlank(object.toString())) {
                throw new BizException(ExceptionEnum.LOGICAL_ERROR, message);
            }
        }
    }
}
