var APIBase = require("../../api.base");
var system = require("../../../system");
var settings = require("../../../../config/settings");
class ActionAPI extends APIBase {
    constructor() {
        super();


        this.saasmainSve = system.getObject("service.main.saasmainSve");
        this.saaschannelSve = system.getObject("service.channel.saaschannelSve");
        this.saasmerchantSve = system.getObject("service.merchant.saasmerchantSve");


        // -------------------------------将要弃用------------------------------------------
        this.merchantSve = system.getObject("service.merchant.merchantSve");
        this.merchantsignedSve = system.getObject("service.merchant.merchantsignedSve");
        this.merchantaccountSve = system.getObject("service.merchant.merchantaccountSve");
        this.merchantrechargeSve = system.getObject("service.merchant.merchantrechargeSve");
        this.merchanttitleSve = system.getObject("service.merchant.merchanttitleSve");
        this.merchantaddressSve = system.getObject("service.merchant.merchantaddressSve");
    }
    /**
     * 接口跳转
     * 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 "mainDics":
                opResult = await this.saasmainSve.dics(action_body);
                break;
            case "mainPage":
                opResult = await this.saasmainSve.pageByCondition(action_body);
                break;
            case "mainInfo":
                opResult = await this.saasmainSve.info(action_body);
                break;
            case "mainSave":
                opResult = await this.saasmainSve.save(action_body);
                break;
            case "mainMapByIds":
                opResult = await this.saasmainSve.mapByIds(action_body);
                break;
    
            // 渠道
            case "channelDics":
                opResult = await this.saaschannelSve.dics(action_body);
                break;
            case "channelPage":
                opResult = await this.saaschannelSve.pageByCondition(action_body);
                break;
            case "channelInfo":
                opResult = await this.saaschannelSve.info(action_body);
                break;
            case "channelSave":
                opResult = await this.saaschannelSve.save(action_body);
                break;
            case "channelMapByIds":
                opResult = await this.saaschannelSve.mapByIds(action_body);
                break;
            // 商户
            case "mchtMapByIds":
                opResult = await this.saasmerchantSve.mapByIds(action_body);
                break;
            case "mchtDics":
                opResult = await this.saasmerchantSve.dics(action_body);
                break;
            case "mchtInfo":
                opResult = await this.saasmerchantSve.info(action_body);
                break;
            case "mchtSignInfo":
                opResult = await this.saasmerchantSve.signInfo(action_body);
                break;
            case "mchtSave":
                opResult = await this.saasmerchantSve.save(action_body);
                break;
            case "mchtPage":
                opResult = await this.saasmerchantSve.pageByCondition(action_body);
                break;
            case "mchtSign":
                opResult = await this.saasmerchantSve.sign(action_body);
                break;
    
            // ------------------------------以下api为历史将要弃用的---------------------------------------
            // 商户api
            // case "infoList":
            //     opResult = await this.merchantSve.apiInfoList(action_body);
            //     break;
            // case "nameList":
            //     opResult = await this.merchantSve.apiNameList(action_body);
            //     break;
            // case "addMerchant":
            //     opResult = await this.merchantSve.apiAddMerchant(action_body);
            //     break;
            // case "getById":
            //     opResult = await this.merchantSve.apiGetMerchant(action_body);
            //     break;
            // case "getMapByIds":
            //     opResult = await this.merchantSve.apiGetMerchantMap(action_body);
            //     break;
            // case "updMerchant":
            //     opResult = await this.merchantSve.apiUpdMerchant(action_body);
            //     break;
            // case "auditMerchant":
            //     opResult = await this.merchantSve.apiAuditMerchant(action_body);
            //     break;
            // case "queryMerchant":
            //     opResult = await this.merchantSve.apiQueryMerchant(action_body);
            //     break;
            // case "secretById":
            //     opResult = await this.merchantSve.apiSecretById(action_body);
            //     break;

            // // 商户签约api
            // case "saveMerchantSign":
            //     opResult = await this.merchantsignedSve.apiSaveSign(action_body);
            //     break;
            // case "merchantSignInfo":
            //     opResult = await this.merchantsignedSve.apiSignInfo(action_body);
            //     break;
            // case "merchantSignList":
            //     opResult = await this.merchantsignedSve.apiSignPage(action_body);
            //     break;

            // // 商户抬头api
            // case "merchantTitleList":
            //     opResult = await this.merchanttitleSve.apiTitlePage(action_body);
            //     break;
            // case "merchantTitleInfo":
            //     opResult = await this.merchanttitleSve.apiTitleInfo(action_body);
            //     break;
            // case "merchantTitleSave":
            //     opResult = await this.merchanttitleSve.apiSaveTitle(action_body);
            //     break;  
            // case "merchantTitleDefault":
            //     opResult = await this.merchanttitleSve.apiSetDefault(action_body);
            //     break;
            // case "getMerchantTitleDefault":
            //     opResult = await this.merchanttitleSve.apiGetDefault(action_body);
            //     break;

            // // 商户地址api
            // case "merchantAddressList":
            //     opResult = await this.merchantaddressSve.apiAddressPage(action_body);
            //     break;
            // case "merchantAddressInfo":
            //     opResult = await this.merchantaddressSve.apiAddressInfo(action_body);
            //     break;
            // case "merchantAddressSave":
            //     opResult = await this.merchantaddressSve.apiSaveAddress(action_body);
            //     break;
            // case "merchantAddressDefault":
            //     opResult = await this.merchantaddressSve.apiSetDefault(action_body);
            //     break;
            // case "getMerchantAddressDefault":
            //     opResult = await this.merchantaddressSve.apiGetDefault(action_body);
            //     break;


            // // 资金账户
            // case "merchantAccountPage":
            //     opResult = await this.merchantaccountSve.apiPage(action_body);
            //     break;
            // case "merchantAccountInfo":
            //     opResult = await this.merchantaccountSve.apiInfo(action_body);
            //     break;
            // case "merchantAccountInfoByMerchantId":
            //     opResult = await this.merchantaccountSve.apiInfoByMerchantId(action_body);
            //     break;


            // // 商户充值api
            // case "merchantRechargePage":
            //     opResult = await this.merchantrechargeSve.apiPage(action_body);
            //     break;
            // case "merchantRechargeAdd":
            //     opResult = await this.merchantrechargeSve.apiAdd(action_body);
            //     break;
            // case "merchantRechargeInfo":
            //     opResult = await this.merchantrechargeSve.apiInfo(action_body);
            //     break;
            // case "merchantRechargeAudit":
            //     opResult = await this.merchantrechargeSve.apiAudit(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;