var APIBase = require("../../api.base");
var system = require("../../../system");
var settings = require("../../../../config/settings");
class ActionAPI extends APIBase {
    constructor() {
        super();
        this.ecloudsignSve = system.getObject("service.sign.ecloudsignSve");
    }
    /**
     * 接口跳转
     * action_process  执行的流程
     * action_type     执行的类型
     * action_body     执行的参数
     */
    async springboard(pobj, qobj, req) {
        var result;
        if (!pobj.action_process) {
            return system.getResult(null, "action_process参数不能为空");
        }
        if (!pobj.action_type) {
            return system.getResult(null, "action_type参数不能为空");
        }
        try {
            result = await this.handleRequest(pobj.action_process, pobj.action_type, pobj.action_body);    
        } catch (error) {
            console.log(error);
        }
        
        return result;
    }

    async handleRequest(action_process, action_type, action_body) {
        var opResult = null;
        switch (action_type) {
            // 三要素 四要素验证
            case "bankVerify":
                opResult = await this.ecloudsignSve.apibankVerify(action_body);
                break;
            //申请证书
            case "applyCert":
                opResult = await this.ecloudsignSve.apiapplyCert(action_body);
                break;
             //添加签名/印章
            case "addSign":
                opResult = await this.ecloudsignSve.apiaddSign(action_body);
                break;
            //自动生成公司印章
            case "createSeal":
                opResult = await this.ecloudsignSve.apicreateSeal(action_body);
                break;
            //  自动生成姓名矩形章
            case  "createSign":
                opResult = await  this.ecloudsignSve.apicreateSign(action_body);
                break;
            //页面手写签字
            case "signPage":
                opResult = await this.ecloudsignSve.apisignPage(action_body);
                break;
            //添加模板
            case "addHtmlTemplate":
                opResult = await this.ecloudsignSve.apiaddHtmlTemplate(action_body);
                break;
            //根据模板生成合同文档
            case "createContractByTemplate":
                opResult = await this.ecloudsignSve.apicreateContractByTemplate(action_body);
                break;
            //合同签署动态验证码发送
            case "sendSms":
                opResult = await this.ecloudsignSve.apisendSms(action_body);
                break;
            //用户授权验证签署合同
            case "authorizeSign":
                opResult = await this.ecloudsignSve.apiauthorizeSign(action_body);
                break;
            //合同详情下载
            case "downloadCont":
                opResult = await this.ecloudsignSve.apidownloadCont(action_body);
                break;


            default:
                opResult = system.getResult(null, "action_type参数错误");
                break;
        }
        return opResult;
    }




    exam() {
        return `<pre><pre/>`;
    }


    classDesc() {
        return {
            groupName: "op",
            groupDesc: "元数据服务包",
            name: "ActionAPI",
            desc: "此类是对外提供接口服务",
            exam: "",
        };
    }
    methodDescs() {
        return [
            {
                methodDesc: `<pre><pre/>`,
                methodName: "springboard",
                paramdescs: [
                    {
                        paramDesc: "请求的行为，传递如：sjb",
                        paramName: "action_process",
                        paramType: "string",
                        defaultValue: null,
                    },
                    {
                        paramDesc: "业务操作类型，详情见方法中的描述",
                        paramName: "action_type",
                        paramType: "string",
                        defaultValue: null,
                    },
                    {
                        paramDesc: "业务操作类型的参数，action_body必须传递的参数有，times_tamp（时间戳，类型int）、sign(签名,类型string)，其余的为业务需要的参数",
                        paramName: "action_body",
                        paramType: "json",
                        defaultValue: null,
                    }
                ],
                rtnTypeDesc: `<pre><pre/>`,
                rtnType: `<pre><pre/>`
            }
        ];
    }
}
module.exports = ActionAPI;