package com.ruoyi.common.utils;

import com.ruoyi.common.exception.CheckException;
import org.springframework.context.MessageSource;

import java.util.Arrays;


/**
 * @author HAIHUA2
 */
public class CheckUtils {
    private static MessageSource resources;

    public static void setResources(MessageSource resources) {
        CheckUtils.resources = resources;
    }

    public static void check(boolean condition, String msgKey, Object... args) {
        if (!condition) {
            fail(msgKey, args);
        }
    }

    public static void notEmpty(String str, String msgKey, Object... args) {
        if (str == null || str.isEmpty()) {
            fail(msgKey, args);
        }
    }

    public static void notNull(Object obj, String msgKey, Object... args) {
        if (obj == null) {
            fail(msgKey, args);
        }
    }

    private static void fail(String msgKey, Object... args) {
        throw new CheckException(msgKey + ": " + Arrays.toString(args));
        //    throw new CheckException(resources.getMessage(msgKey, args, Locale.CHINA));
    }
}
