package com.tax.user.service.safe.impl;


import com.yxcheng.token.common.model.CrRpcResult;
import com.yxcheng.token.common.model.RestfulApi;
import com.tax.user.service.safe.RestFulCheckI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by 曹小红 on 2017-04-11.
 */
@Component
public class RestFulCheckService{

    protected static Logger logger = LoggerFactory.getLogger(RestFulCheckService.class);

    @Autowired
    List<RestFulCheckI> restFulCheckList;

    public boolean checkData(String data, RestfulApi apiModel, CrRpcResult<String> rpcResult) {
        boolean flag = true;
        for(RestFulCheckI restFulCheck:restFulCheckList) {
            if(!restFulCheck.checkData(data, apiModel, rpcResult)) {
                flag = false;
                logger.info(apiModel.getSignatureNonce() + " request failure!" + rpcResult.getCode() + "-" + rpcResult.getMessage());
                break;
            }
        }
        return flag;
    }

}
