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 org.springframework.util.CollectionUtils;

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

/**
 * @author stayAnd
 * @date 2022/6/7
 */
@Component("checkVinNotExistCheckHandler")
public class CheckVinNotExistCheckHandler 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();
		List<MgRnrCardInfoDTO> rnrCardList = mgRnrCardInfoList.stream()
				.filter(card -> card.getRnrStatus() == RnrStatus.RNR.getCode()).collect(Collectors.toList());
		if (CollectionUtils.isEmpty(rnrCardList)) {
			throw new CuscUserException("", "该vin号未查询到实名的卡信息");
		}
	}
}
