import { NetManager } from './../libs/tw/manager/NetManager';
import { DataManager } from './../libs/tw/manager/DataManager';
import { INetData } from './../libs/tc/interface/INetData';
/**
 * 接口常量
 *
 * 普通游戏接口
 * hdtool/recon/ajaxElement
 * hdtool/recon/doJoin
 * hdtool/recon/ngame/getNgameStartStatus 游戏开始状态
 * hdtool/recon/ngame/ngameSubmit
 * hdtool/recon/getOrderStatus
 *
 * 游戏支持复活 调用接口说明
 * hdtool/recon/ajaxElement
 * hdtool/recon/doJoin
 * hdtool/recon/ngame/getNgameStartStatus 游戏开始状态
 * hdtool/recon/ngame/resurrectionStatus 复活状态 参数dojion中orderId
 *
 * 复活流程
 * hdtool/recon/ngame/resurrection 游戏复活接口 参数dojion中orderId 返回 复活id
 * hdtool/recon/ngame/resurrectionStatus 复活状态 参数dojion中orderId，复活id 返回 复活状态 剩余复活次数 下一次复活所需积分（轮询）
 *
 * 多次领奖流程
 * hdtool/recon/ngame/ngameManySubmit 游戏多次发奖接口 参数dojion中orderId 返回多次领奖orderId
 * hdtool/recon/getOrderStatus 参数多次领奖返回的orderId
 */
export class gdNet{
/**
     * 停留时长
     * @param remain 停留时长
     * @param first 是否第一次进入
     * @param from 来源
     */
    public static remainDuration(remain, first, from = 1): void {
        const net: INetData = {
            name: 'remainDuration',
            uri: '/customActivity/api/remainDuration',
            type: 'get',
            dataType: 'html',
            param: {
                activityId: window["CFG"].activityId,
                activityType: '60000',
                remain: remain,
                first: first,
                from: from
            },
            callback: null,
            hideMsg: true
        };
        NetManager.ins.send(net);
    }
}
export class iqiyi{
    /**
     * 1.1万能卡兑换
     * @param callback 回调
     */
    public static exchange(callback, activityId, toId){
        const net: INetData = {
            name: 'exchange',
            uri: `/customActivity/iqiyi/scream/exchange`,
            type: 'post',
            dataType: 'json',
            hideMsg: true,
            param: {
                activityId:activityId,
                toId:toId
            },
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.2助力
     * @param callback 回调
     */
    public static doHelp(callback, activityId, shareCode){
        const net: INetData = {
            name: 'doHelp',
            uri: `/customActivity/iqiyi/scream/doHelp`,
            type: 'post',
            dataType: 'json',
            hideMsg: true,
            param: {
                activityId:activityId,
                shareCode:shareCode
            },
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.3卡片合成
     * @param callback 回调
     */
    public static merge(callback, activityId){
        const net: INetData = {
            name: 'merge',
            uri: `/customActivity/iqiyi/scream/merge`,
            type: 'post',
            dataType: 'json',
            hideMsg: true,
            param: {
                activityId:activityId
            },
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.4抽卡
     * @param callback 回调
     */
    public static collect(callback, activityId){
        let param: any = {
            activityId: activityId

        }
        const net: INetData = {
            name: 'collect',
            uri: `/customActivity/iqiyi/scream/collect`,
            type: 'post',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.5收取卡片
     * ticketNum 扣积分门票凭证
     * @param callback 回调
     */
    public static receive(callback, activityId, shareCode, cardId, token){
        let param: any = {
            activityId: activityId,
            shareCode:shareCode,
            cardId:cardId,
            token:token
        }
        const net: INetData = {
            name: 'receive',
            uri: `/customActivity/iqiyi/scream/receive`,
            type: 'post',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.6完成任务
     * @param callback 回调
     */
    public static doTask(callback, activityId, code){
        let param: any = {
            activityId: activityId,
            code:code
        }
        const net: INetData = {
            name: 'doTask',
            uri: `/customActivity/iqiyi/scream/doTask`,
            type: 'post',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }

    /**
     * 1.7获取token
     * @param callback 回调
     */
    public static getToken(callback, activityId){
        let param: any = {
            activityId:activityId
        }
        const net: INetData = {
            name: 'getToken',
            uri: `/customActivity/iqiyi/scream/getToken`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.8获取任务信息
     * @param callback 回调
     */
    public static getTasks(callback, activityId){
        let param: any = {
            activityId:activityId
        }
        const net: INetData = {
            name: 'getTasks',
            uri: `/customActivity/iqiyi/scream/getTasks`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.9获取分享码
     * @param callback 回调
     */
    public static getShareCode(callback, activityId,type){
        let param: any = {
            activityId:activityId,
            type:type
        }
        const net: INetData = {
            name: 'getShareCode',
            uri: `/customActivity/iqiyi/scream/getShareCode`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.10获取已集齐人数
     * @param callback 回调
     */
    public static getCompletedNum(callback, activityId){
        let param: any = {
            activityId:activityId
        }
        const net: INetData = {
            name: 'getCompletedNum',
            uri: `/customActivity/iqiyi/scream/getCompletedNum`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.11获取所有卡片列表
     * @param callback 回调
     */
    public static getAllCards(callback, activityId){
        let param: any = {
            activityId:activityId
        }
        const net: INetData = {
            name: 'getAllCards',
            uri: `/customActivity/iqiyi/scream/getAllCards`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.12获取集卡次数
     * @param callback 回调
     */
    public static getCollectNum(callback, activityId){
        let param: any = {
            activityId:activityId
        }
        const net: INetData = {
            name: 'getCollectNum',
            uri: `/customActivity/iqiyi/scream/getCollectNum`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.13赠送卡片
     * @param callback 回调
     */
    public static give(callback, activityId, shareCode, cardId){
        let param: any = {
            activityId:activityId,
            shareCode:shareCode,
            cardId:cardId
        }
        const net: INetData = {
            name: 'give',
            uri: `/customActivity/iqiyi/scream/give`,
            type: 'post',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.13获取开奖结果
     * @param callback 回调
     */
    public static getOpenResult(callback, activityId){
        let param: any = {
            activityId:activityId
        }
        const net: INetData = {
            name: 'getOpenResult',
            uri: `/customActivity/iqiyi/scream/getOpenResult`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.14轮询订单状态
     * @param callback 回调
     */
    public static getOrderStatus(callback, orderId){
        let param: any = {
            orderId:orderId
        }
        const net: INetData = {
            name: 'getOrderStatus',
            uri: `/hdtool/recon/getOrderStatus`,
            type: 'post',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
}



export default class NetConst {

    public static ajaxElement(callback) {
        const net: INetData = {
            name: 'gameAjaxElement',
            uri: '/hdtool/recon/ajaxElement',
            type: 'get',
            dataType: 'json',
            param: {
                duibaId: window['turn_hdToolId'],
                activityId: window['turn_actId']
            },
            callback: callback
        };
        NetManager.ins.send(net);
    }

    /**
     * 获取排行榜列表
     * @param callback 回调
     * @param rankId 排行榜id
     * @param hdtoolId 活动工具id
     */
    public static getRankList(callback: Function, rankId: any, hdtoolId: any): void {
        const param: any = {
            rankId: rankId,
            hdtoolId: hdtoolId
        };
        const net: INetData = {
            name: 'rankList',
            uri: '/hdtool/rank/rankList',
            type: 'get',
            dataType: 'json',
            param: param,
            hideMsg: true,
            callback: callback
        };
        NetManager.ins.send(net);
    }

    /**
     * 获取排行榜列表
     * @param callback 回调
     * @param rankId 排行榜id
     * @param activityId cfg oaid
     * @param needPreviousPeriod 是否需要上期排行榜数据
     * @param pageNo
     * @param pageSize
     */
    public static recentRankList(callback: Function, rankId: number, activityId: number, needPreviousPeriod: boolean = false, pageNo: number = 0, pageSize: number = 50): void {
        const param: any = {
            rankId: rankId,
            activityId: activityId,
            needPreviousPeriod: needPreviousPeriod,
            pageNo: pageNo,
            pageSize: pageSize
        };
        const net: INetData = {
            name: 'recentRankList',
            uri: '/hdtool/rank/recentRankListNew',
            type: 'get',
            dataType: 'json',
            param: param,
            hideMsg: true,
            callback: callback
        };
        NetManager.ins.send(net);
    }


    /**
     * 参与游戏
     * @param callback 回调
     * @param credits 积分
     * @param collectRuleId 集卡规则id？
     */
    public static doJoin(callback: Function, activityId = DataManager.ins.customCfgData.actId, credits?: number, collectRuleId?: number): void {
        const param: any = {
            activityId: window['turn_actId'],
            activityType: 'hdtool',
            consumerId: DataManager.ins.customCfgData.consumerId
        };
        if (credits) {
            param.credits = credits;
        }
        if (collectRuleId) {
            param.collectRuleId = collectRuleId;
        }
        const net: INetData = {
            name: 'doJoin',
            uri: '/hdtool/recon/doJoin',
            type: 'post',
            dataType: 'json',
            param: param,
            hideMsg: true,
            callback: callback
        };
        NetManager.ins.getToken(net);
    }

    public static doJoin2(callback: Function, activityId = DataManager.ins.customCfgData.actId, credits?: number, collectRuleId?: number): void {
        const param: any = {
            activityId: window['turn_actId'],
            activityType: 'hdtool',
            consumerId: DataManager.ins.customCfgData.consumerId
        };
        if (credits) {
            param.credits = credits;
        }
        if (collectRuleId) {
            param.collectRuleId = collectRuleId;
        }
        const net: INetData = {
            name: 'doJoin',
            uri: '/hdtool/recon/doJoin',
            type: 'post',
            dataType: 'json',
            param: param,
            hideMsg: true,
            callback: callback
        };
    }

    /**
     * 轮询开始状态
     * @param callback 回调
     * @param orderId 订单id
     */
    public static getNgameStartStatus(callback: Function, orderId: number, pollingCheck: Function, pollingCount = 10): void {
        const param: any = {
            orderId: orderId
        };
        const net: INetData = {
            name: 'getNgameStartStatus',
            uri: '/hdtool/recon/ngame/getNgameStartStatus',
            type: 'post',
            dataType: 'json',
            param: param,
            hideMsg: true,
            callback: callback,
            pollingCheck: pollingCheck,
            pollingCount: pollingCount
        };
        NetManager.ins.send(net);
    }

    /**
     * 发送得分
     * @param callback 回调
     * @param orderId 订单id
     * @param score 分数
     * @param gameData 游戏数据
     * @param dynamicData 动态数据
     * @param submitToken 提交数据token  由 getNgameStartStatus 返回
     */
    public static ngameSubmit(callback: Function, orderId: number, score: number, gameData: any, dynamicData: any, submitToken: string, rankId?: number): void {
        const sign = NetManager.ins['createSgin'](orderId, score, gameData, submitToken);
        const param: any = {
            orderId: orderId,
            score: score,
            gameData: gameData,
            sgin: sign,
            dynamicData: JSON.stringify(dynamicData)
        };
        if (rankId) {
            param.rankId = rankId;
        }
        const net: INetData = {
            name: 'ngameSubmit',
            uri: '/hdtool/recon/ngame/ngameSubmit',
            type: 'post',
            dataType: 'json',
            param: param,
            hideMsg: true,
            callback: callback
        };
        NetManager.ins.send(net);
    }

    /**
     * 游戏多次领奖
     * @param callback 回调
     * @param orderId 订单号
     * @param score 分数
     * @param gameData 游戏数据
     * @param dynamicData 动态数据
     * @param submitToken 提交数据token  由 getNgameStartStatus 返回
     * @param rankId 排行id
     */
    public static ngameManySubmit(callback: Function, orderId: number, score: number, gameData: any, dynamicData: any, submitToken: string, rankId?: number): void {
        const sign = NetManager.ins['createSgin'](orderId, score, gameData, submitToken);
        const param: any = {
            orderId: orderId,
            score: score,
            gameData: gameData,
            sgin: sign,
            dynamicData: JSON.stringify(dynamicData)
        };
        if (rankId) {
            param.rankId = rankId;
        }
        const net: INetData = {
            name: 'ngameManySubmit',
            uri: '/hdtool/recon/ngame/ngameManySubmit',
            type: 'post',
            dataType: 'json',
            param: param,
            hideMsg: true,
            callback: callback
        };
        NetManager.ins.send(net);
    }

    /**
     * 游戏数据校验防作弊
     * @param callback 回调
     * @param orderId 订单id
     * @param dynamicData 动态数据
     * @param duibaId duiba活动id
     */
    public static datapash(callback: Function, orderId: number, dynamicData: any): void {
        const param: any = {
            orderId: orderId,
            dynamicData: dynamicData,
            duibaId: window['CFG'].hdToolId
        };
        const net: INetData = {
            name: 'datapash',
            uri: '/hdtool/recon/ngame/datapash',
            type: 'post',
            dataType: 'json',
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }

    /**
     * 复活接口
     * @param callback 回调
     * @param orderId 订单id
     */
    public static resurrection(callback: Function, orderId: number): void {
        const param: any = {
            orderId: orderId
        };
        const net: INetData = {
            name: 'resurrection',
            uri: '/hdtool/recon/ngame/resurrection',
            type: 'post',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }

    /**
     * 轮询复活状态
     * @param callback 回调
     * @param orderId 订单id
     * @param pollingCheck 轮询条件
     * @param pollingCount 轮询次数
     * @param resurrecOrderId 复活订单id
     */
    public static resurrectionStatus(callback: Function, orderId: number, pollingCheck?: Function, pollingCount = 10, resurrecOrderId = -1): void {
        const param: any = {
            orderId: orderId
        };
        const net: INetData = {
            name: 'resurrectionStatus',
            uri: '/hdtool/recon/ngame/resurrectionStatus',
            type: 'post',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback,
            pollingCheck: pollingCheck,
            pollingCount: pollingCount
        };
        if (resurrecOrderId != -1) {
            net.param.resurrecOrderId = resurrecOrderId;
        }
        NetManager.ins.send(net);
    }

    /**
     * 轮询订单状态
     * @param callback 回调
     * @param orderId 订单id
     */
    public static getOrderStatus(callback: Function, orderId: any, pollingCheck?: Function, pollingCount = 10): void {
        const param: any = {
            orderId: orderId
        };
        const net: INetData = {
            name: 'getOrderStatus',
            uri: '/hdtool/recon/getOrderStatus',
            type: 'post',
            dataType: 'json',
            param: param,
            hideMsg: true,
            callback: callback,
            pollingCheck: pollingCheck,
            pollingCount: pollingCount
        };
        NetManager.ins.send(net);
    }

    /**
     * 招商银行钓龙虾定制接口
     * @param callback 回调
     * @param activityId 活动id cfg oaid
     * @param score 分数
     * @param shareCode 分享码
     */
    public static shrimpFishingIndex(callback: Function, activityId: number, score?: number, shareCode?: string): void {
        const param: any = {
            activityId: activityId
        };
        if (score) {
            param.score = score;
        }
        if (shareCode) {
            param.shareCode = shareCode;
        }
        const net: INetData = {
            name: 'shrimpFishingIndex',
            uri: '/aaw/changshaCmb/shrimpFishing/index',
            type: 'get',
            dataType: 'json',
            param: param,
            hideMsg: true,
            callback: callback
        };
        NetManager.ins.send(net);
    }
}