package com.muyu.data.mart.service.impl;

import com.muyu.data.mart.common.BasicApi;
import com.muyu.data.mart.domain.realname.RealNameReq;
import com.muyu.data.mart.domain.realname.RealNameResp;
import com.muyu.data.mart.remote.AliRemoteService;
import com.muyu.data.mart.remote.JuHeRemoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashSet;
import java.util.Set;

/**
 * @Author：chaiyapeng
 * @Package：com.muyu.data.mart.service.impl
 * @Project：cloud-port
 * @name：RealNameServiceImpl
 * @Date：2024/9/10 10:03
 */
@Service(value = "source-real-name")
public class RealNameServiceImpl implements BasicApi<RealNameReq, RealNameResp> {

    @Resource
    private JuHeRemoteService juHeRemoteService;

    @Resource
    private AliRemoteService aliRemoteService;

    private static final Set<String> realNameSet=new HashSet<>(){{
        add("张三-123456789123456712");
        add("李四-123456789123456713");
        add("王五-123456789123456714");
        add("赵六-123456789123456715");
        add("田七-123456789123456716");
    }};
    @Override
    public RealNameResp send(RealNameReq realNameReq) {
        //改为去数据库查询
        String nameAndIdCard = realNameReq.getName() + "-" + realNameReq.getIdCard();
        if (realNameSet.contains(nameAndIdCard)) {
            // 如果存在，则返回验证失败的消息
            return RealNameResp.builder()
                    .code("0")
                    .mag("验证成功")
                    .build();
        }
        //主从辅
        RealNameResp realNameResp = juHeRemoteService.realName(realNameReq);
        if (!realNameResp.getCode().equals(0) && !realNameResp.getMag().equals("成功")){
            RealNameResp realNameResp1 = aliRemoteService.realName(realNameReq);
            if (!realNameResp1.getCode().equals(1) && !realNameResp1.getMag().equals("认证成功")){
                throw new RuntimeException("线路正在抢修中！！！");
            }
            return realNameResp1;
        }else {
            return realNameResp;
        }
    }
}
