package com.persagy.dmp.common.utils;

import com.persagy.dmp.common.constant.CommonConstant;
import com.persagy.dmp.common.constant.ResponseCode;
import com.persagy.dmp.common.context.AppContext;
import com.persagy.dmp.common.exception.BusinessException;
import org.springframework.util.StringUtils;

public class ParamCheckUtil {

    public static void checkParam(String... requestParams) {
        if (requestParams == null) {
            return;
        }
        String groupCode = AppContext.getContext().getGroupCode();
        String projectId = AppContext.getContext().getProjectId();
        String appId = AppContext.getContext().getAppId();
        String accountId = AppContext.getContext().getAccountId();

        for (String paramName : requestParams) {
            if (CommonConstant.QUERY_GROUPCODE.equals(paramName) && StringUtils.isEmpty(groupCode)) {
                throw new BusinessException(ResponseCode.A0400.getCode(), "集团编码不可为空");
            }

            if (CommonConstant.QUERY_PROJECTID.equals(paramName) && StringUtils.isEmpty(projectId)) {
                throw new BusinessException(ResponseCode.A0400.getCode(), "项目ID不可为空");
            }

            if (CommonConstant.QUERY_USERID.equals(paramName) && StringUtils.isEmpty(accountId)) {
                throw new BusinessException(ResponseCode.A0400.getCode(), "用户ID不可为空");
            }

            if (CommonConstant.QUERY_APPID.equals(paramName) && StringUtils.isEmpty(appId)) {
                throw new BusinessException(ResponseCode.A0400.getCode(), "应用ID不可为空");
            }
        }
    }
}
