package cn.meowrain.aioj.backend.auth.dto.chains;

import cn.meowrain.aioj.backend.auth.common.enums.ChainMarkEnums;
import cn.meowrain.aioj.backend.auth.dto.req.UserLoginRequestDTO;

import cn.meowrain.aioj.backend.framework.core.designpattern.chains.AbstractChianHandler;
import cn.meowrain.aioj.backend.framework.core.errorcode.ErrorCode;
import cn.meowrain.aioj.backend.framework.core.exception.ClientException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class UserLoginRequestParamVerifyChain implements AbstractChianHandler<UserLoginRequestDTO> {

	@Override
	public void handle(UserLoginRequestDTO requestParam) {
		if (StringUtils.isAnyBlank(requestParam.getUserAccount(), requestParam.getUserPassword())) {
			throw new ClientException("参数为空", ErrorCode.PARAMS_ERROR);
		}
		if (requestParam.getUserAccount().length() < 4) {
			throw new ClientException("账号长度不小于4位", ErrorCode.PARAMS_ERROR);
		}
		if (requestParam.getUserPassword().length() < 8) {
			throw new ClientException("密码长度不小于8位", ErrorCode.PARAMS_ERROR);
		}
	}

	@Override
	public String mark() {
		return ChainMarkEnums.USER_LOGIN_REQ_PARAM_VERIFY.getMarkName();
	}

	@Override
	public int getOrder() {
		return 10;
	}

}
