package com.tax.file.utils.token;

import com.tax.file.model.FileServer;
import com.tax.file.model.TkTaxUser;
import com.tax.file.model.token.TokenInfoModel;
import com.yxcheng.token.utils.JSONHelper;
import com.yxcheng.token.utils.ResponseContent;
import org.apache.http.HttpException;
import org.apache.log4j.Logger;

import java.io.IOException;
import java.util.Map;

public abstract class AbstractTokenService implements TokenService {
    private  final Logger logger = Logger.getLogger(this.getClass());

    @Override
    public TokenInfoModel getToken(TkTaxUser tkTaxUser, FileServer fileServer) throws IOException, HttpException {
        ResponseContent ret = invoke(tkTaxUser,fileServer);
        logger.info("runGetToken " + tkTaxUser.getTaxno() + " result info is : " + ret.getContent() + ", tokenFrom is : " + fileServer.getTokenFrom());
        String retStr = ret.getContent();
        Map<String, Object> retMap = JSONHelper.parserToMap(retStr);
        return getResult(retMap);
    }

    protected abstract TokenInfoModel getResult(Map<String, Object> retMap);


    protected abstract ResponseContent invoke(TkTaxUser tkTaxUser, FileServer fileServer) throws IOException, HttpException;

}
