package com.cusc.nirvana.user.rnr.fp.handler.impl;

import com.cusc.nirvana.common.result.Response;
import com.cusc.nirvana.user.exception.CuscUserException;
import com.cusc.nirvana.user.rnr.mg.client.MgRnrCardInfoClient;
import com.cusc.nirvana.user.rnr.mg.constants.RnrStatus;
import com.cusc.nirvana.user.rnr.mg.dto.MgRnrCardInfoDTO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author stayAnd
 * @date 2022/6/7
 */
@Component("checkVinExistCheckHandler")
public class CheckVinExistCheckHandler extends CommonBindVinCardCheckHandlerImpl {

	@Resource
	private MgRnrCardInfoClient cardInfoClient;


	@Override
	protected void checkVin(String vin) {
		MgRnrCardInfoDTO query = new MgRnrCardInfoDTO();
		query.setIotId(vin);
		Response<List<MgRnrCardInfoDTO>> response = cardInfoClient.queryByList(query);
		if (null == response || !response.isSuccess()) {
			throw new CuscUserException("","查询卡信息失败");
		}
		List<MgRnrCardInfoDTO> mgRnrCardInfoList = response.getData();

		//自然人 - 新车 || 企业实名 || 车企实名
		if (mgRnrCardInfoList.stream().anyMatch(
				card -> RnrStatus.INIT.getCode() == card.getRnrStatus() || RnrStatus.RNR.getCode() == card.getRnrStatus())) {
//			throw new CuscUserException("", "vin已经存在实名信息,请走一车多卡流程");
			throw new CuscUserException("", "您提交的VIN号已实名，请勿重复提交实名！");
		}
	}
}
