package com.huimv.video.dhicc.test.service.impl;

import com.huimv.video.dhicc.test.manager.IOauthIntegrationManager;
import com.huimv.video.dhicc.test.other.BaseService;
import com.huimv.video.dhicc.test.request.GetPublicKeyRes;
import com.huimv.video.dhicc.test.response.GetPublicKeyResponse;
import com.huimv.video.dhicc.test.response.GetTokenResponse;
import com.huimv.video.dhicc.test.service.IOauthService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class OauthService extends BaseService implements IOauthService {

    @Autowired
    private IOauthIntegrationManager oauthIntegrationManager;

    /**
     * 获取公钥
     **/
    @Override
    public GetPublicKeyRes getPublicKey() {
        GetPublicKeyResponse response = oauthIntegrationManager.getPublicKey();
        GetPublicKeyRes res = new GetPublicKeyRes();
        if(response.isSuccess()){
            //处理成功逻辑
        }else{
            //处理异常逻辑
        }
        BeanUtils.copyProperties(response,res);
        return res;
    }

  /*  *//**
     * 获取token
     **//*
    public GetTokenResponse getToken() {
        GetTokenResponse response = oauthIntegrationManager.getToken();
        if(response.isSuccess()){
            //处理成功逻辑
        }else{
            //处理异常逻辑
        }
        GetTokenResponse res = new GetTokenResponse();
        BeanUtils.copyProperties(response,res);
        return res;
    }*/

    /**
     * 获取token
     **/
    @Override
    public String getTokenTest01(Map<String,String> paramsMap) {
        String type = paramsMap.get("type");
        if ("1".equals(type)) {
            System.out.println("曙光");
            GetTokenResponse response = oauthIntegrationManager.getTokenTest01();
            if(response.isSuccess()){
                //处理成功逻辑
            }else{
                //处理异常逻辑
            }
            String access_token = response.getData().getAccess_token();
            GetTokenResponse res = new GetTokenResponse();
            BeanUtils.copyProperties(response,res);
            return ("token:"+access_token);
        } else if ("2".equals(type)) {
            System.out.println("海宁");
            GetTokenResponse response = oauthIntegrationManager.getTokenTest02();
            if (response.isSuccess()) {
                //处理成功逻辑
            } else {
                //处理异常逻辑
            }
            String access_token = response.getData().getAccess_token();
            GetTokenResponse res = new GetTokenResponse();
            BeanUtils.copyProperties(response, res);
            return ("token:" + access_token);
        } else {
            System.out.println("苍南");
            GetTokenResponse response = oauthIntegrationManager.getTokenTest03();
            if (response.isSuccess()) {
                //处理成功逻辑
            } else {
                //处理异常逻辑
            }
            String access_token = response.getData().getAccess_token();
            GetTokenResponse res = new GetTokenResponse();
            BeanUtils.copyProperties(response, res);
            return ("token:" + access_token);
        }

    }

    /**
     * 获取token
     **/
    @Override
    public GetTokenResponse getTokenTest02() {
        GetTokenResponse response = oauthIntegrationManager.getTokenTest02();
        if(response.isSuccess()){
            //处理成功逻辑
        }else{
            //处理异常逻辑
        }
        GetTokenResponse res = new GetTokenResponse();
        BeanUtils.copyProperties(response,res);
        return res;
    }
}
