var APIBase = require("../../api.base");
var system = require("../../../system");
var settings = require("../../../../config/settings");

class ActionAPI extends APIBase {
    constructor() {
        super();
        this.merchantSve = system.getObject("service.merchant.merchantSve");
        this.merchantapiSve = system.getObject("service.merchant.merchantapiSve");
        this.merchanttradeSve = system.getObject("service.merchant.merchanttradeSve");
        this.merchantaccountSve = system.getObject("service.merchant.merchantaccountSve");
    }

    /**
     * 接口跳转
     * 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 "addModifyMerchants":
                opResult = await this.merchantSve.addModifyMerchants(action_body);
                break;
            //商户列表
            case "merchantOfList":
                opResult = await this.merchantSve.merchantOfList(action_body);
                break;
            //获取商户信息
            case "merchantOfInfo":
                opResult = await this.merchantSve.merchantOfInfo(action_body);
                break;
            case "merchantToIdsInfo":
                opResult = await this.merchantSve.merchantToIdsInfo(action_body);
                break;
            //商户审核
            case "auditMerchant":
                opResult = await this.merchantSve.auditMerchant(action_body);
                break;
            //商户名称
            case "merchantSuggest":
                opResult = await this.merchantSve.merchantSuggest(action_body);
                break;
            //根据商户ID查询商户信息MAP
            case "merchantMapByIds":
                opResult = await this.merchantSve.merchantMapByIds(action_body);
                break;
            //资金调账
            // 新增充值
            case "addMerchanttrades":
                opResult = await this.merchanttradeSve.addMerchanttrades(action_body);
                break;
            //资金调账列表
            case "merchanttradesOfList":
                opResult = await this.merchanttradeSve.merchanttradesOfList(action_body);
                break;
            //审核
            case "auditMerchanttrade":
                opResult = await this.merchanttradeSve.auditMerchanttrade(action_body);
                break;

             //资金流水
             //资金流水
            case "merchanttradesOfListAll":
                opResult = await this.merchanttradeSve.merchanttradesOfListAll(action_body);
                break;
            //代客下单流水
            case "valetorder":
                opResult = await this.merchanttradeSve.valetorder(action_body);
                break;
            //商户余额
            //余额
            case "reduceAccountBalance" :
                opResult = await this.merchantaccountSve.reduceaccountbalance(action_body);
                break;
            //可用余额
            case "addordelavailable" :
                opResult = await this.merchantaccountSve.addordelavailable(action_body);
                break;
            //商户账户
            case "merchantAccountList" :
                opResult = await this.merchantaccountSve.merchantAccountList(action_body);
                break;

            // api信息查询
            case "apiInfoById" :
                opResult = await this.merchantapiSve.infoById(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;
