package com.tax.token.web.controller;

import com.tax.token.model.SignModel;
import com.tax.token.model.SignReq;
import com.tax.token.service.api.SignService;
import com.yxcheng.token.common.controller.BaseClientController;
import com.yxcheng.token.common.enumutil.ResultEnum;
import com.yxcheng.token.common.model.JsonResult;
import com.yxcheng.token.constants.RestFulApiContants;
import com.yxcheng.token.utils.ObjectUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 签名服务统一入口
 */
@RestController
@RequestMapping("/signService")
@ComponentScan(basePackages = {"com.tax.sign.service"})
public class SignController extends BaseClientController {
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private SignService signService;
    @RequestMapping(value ="/getLoginSign" , method = RequestMethod.GET)
    public JsonResult<SignModel> getLoginSign(SignReq signReq){
        if(!ObjectUtil.checkData(signReq.getTaxno(),signReq.getDqdm(),signReq.getServerRandom())){
            return new JsonResult().errorResponse(ResultEnum.param_error);
        }
        if(StringUtils.isBlank(signReq.getUserName())){
            signReq.setUserName(signReq.getAccessKeyID());
        }
        signReq.setApplyFunction(RestFulApiContants.SIGN);
        return signService.getLoginSign(signReq,request);
    }


}
