package com.ywt.alipaympapi.core.utils;


import com.ywt.alipaympapi.models.Constants;
import com.ywt.core.exception.AppMessageException;

/**
 * @author Walker
 * Created on 2019/7/5
 */
public final class CheckUtil {
    public static void ensureNotEmpty(String val, String msg) throws AppMessageException {
        if (StringHelper.isNullOrEmpty(val)) throw new AppMessageException(msg);
    }

    public static void ensureStringLength(String val, int length, String msg) throws AppMessageException {
        if (Checker.getStringValue(val).trim().length() > length) throw new AppMessageException(msg);
    }

    public static void ensureLargerThanZero(Integer val, String msg) throws AppMessageException {
        if (Checker.getIntegerValue(val) <= 0) throw new AppMessageException(msg);
    }

    public static void ensurePositive(Integer val, String msg) throws AppMessageException {
        if (Checker.getIntegerValue(val) < 0) throw new AppMessageException(msg);
    }

    public static void ensureLargerThanZero(Double val, String msg) throws AppMessageException {
        if (Checker.getDoubleValue(val) <= 0) throw new AppMessageException(msg);
    }

    public static void ensureLargerThanZero(Long val, String msg) throws AppMessageException {
        if (Checker.getLongValue(val) <= 0) throw new AppMessageException(msg);
    }

    public static void ensureValidPhoneNumber(String val, String msg) throws AppMessageException {
        if (!PhoneNumChecker.isPhoneNum(Checker.getStringValue(val))) throw new AppMessageException(msg);
    }

    public static void ensureNotNull(Object obj, String msg) throws AppMessageException {
        if (obj == null) throw new AppMessageException(msg);
    }

    public static void limitString100(String val, String msg) throws AppMessageException {
        ensureStringLength(val, Constants.INPUT_TEXT_LENGTH_100, msg);
    }

    public static void limitString30(String val, String msg) throws AppMessageException {
        ensureStringLength(val, Constants.INPUT_TEXT_LENGTH_30, msg);
    }

}
