package cn.superdesk.uniorder.common.exception.utils;

import cn.superdesk.uniorder.common.exception.UnifiedOrderRuntimeException;
import cn.superdesk.uniorder.common.exception.constants.ExceptionMsg;

/**
 * @Description: 断言 计划弃用
 * @Author: linjinyu
 * @CreateDate: 8/20/20 4:03 PM
 * @UpdateUser: linjinyu
 * @UpdateDate: 8/20/20 4:03 PM
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
public class AssertUtils {

	public static void isTrue(boolean expression, int code, String message) {
		if (!expression) {
			throw new UnifiedOrderRuntimeException(code, message);
		}
	}


	public static void isNull(Object object, String message) {
		if (object != null) {
			throw new UnifiedOrderRuntimeException(ExceptionMsg.RECORD_EXISTED.getCode(), message);
		}
	}

	public static void isNull(Object object) {
		isNull(object, ExceptionMsg.RECORD_EXISTED.getMsg());
	}

	public static void notNull(Object object, String message) {
		if (object == null) {
			throw new UnifiedOrderRuntimeException(ExceptionMsg.RECORD_NOT_EXIST.getCode(), message);
		}
	}

	public static void notNull(Object object) {
		notNull(object, ExceptionMsg.RECORD_NOT_EXIST.getMsg());
	}


	public static void notBlank(String expression, String message) {
		if (expression == null || "".equals(expression.trim())) {
			throw new UnifiedOrderRuntimeException(ExceptionMsg.REQUEST_PARAM_REQUIRED.getCode(), message);
		}
	}

	public static void notInitData(int id) {
		if (id < 10000) {
			throw new UnifiedOrderRuntimeException(ExceptionMsg.OPTER_NOT_ALLOW.getCode(), "默认数据禁止当前操作");
		}
	}

}
