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 java.util.HashSet;
import java.util.Set;

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

    @Autowired
    private AliRemoteService aliRemoteService;
    @Autowired
    private JuHeRemoteService juHeRemoteService;

    private static final Set<String> realNameSet = new HashSet<String>(){{

        add("张三-12345678912345678");
        add("李四-12345678912345678");
        add("王五-12345678912345678");
        add("赵六-123456712345678");
        add("田七-12345678912345678");
        add("张三-12345678912345678");
    }};
    /**
     * 实名认证 请求
     * @param realNameReq
     * @return
     */
    @Override
    public RealNameResp send(RealNameReq realNameReq) {
          if (realNameSet.add(realNameReq.getName()+realNameReq.getIdCard())){
              return RealNameResp.builder()
                      .code("0")
                      .mag("验证成功")
                      .build();
          }
          //主从辅
        if (realNameSet.size() < 10) {
            return aliRemoteService.realName(realNameReq);
        }
        throw new RuntimeException("线路正在抢修中！！！");
    }
}
