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 yzwNet{
    /**
     * 1.1首页基础信息 
     * @param callback 回调
     */
    public static homeBaseInfo(callback, projectId){
        const net: INetData = {
            name: 'homeBaseInfo',
            uri: `/projectx/${projectId}/join_1/homeBaseInfo.do`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: {
            },
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.2领取宝箱奖励
     * @param callback 回调
     */
    public static getTreasureBox(callback, projectId){
        const net: INetData = {
            name: 'getTreasureBox',
            uri: `/projectx/${projectId}/join_1/getTreasureBox.do`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: {
            },
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.3轮询被邀请人的动画状态 
     * @param callback 回调
     */
    public static pollingAnimationState(callback, projectId,shareCode){
        const net: INetData = {
            name: 'pollingAnimationState',
            uri: `/projectx/${projectId}/invite_2/pollingAnimationState.do`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: {
                shareCode:shareCode
            },
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.4解锁地区 	
     * @param callback 回调
     */
    public static unlockArea(callback, projectId){
        let param: any = {
            
        }
        const net: INetData = {
            name: 'unlockArea',
            uri: `/projectx/${projectId}/join_1/unlockArea.do`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.5被邀请人更改动画状态 
     * @param callback 回调
     */
    public static updateAnimationState(callback, projectId,shareCode,state){
        let param: any = {
            shareCode:shareCode,
            state:state
        }
        const net: INetData = {
            name: 'updateAnimationState',
            uri: `/projectx/${projectId}/invite_2/updateAnimationState.do`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.6邀请码
     * @param callback 回调
     */
    public static genInvite(callback, projectId){
        let param: any = {
        }
        const net: INetData = {
            name: 'genInvite',
            uri: `/projectx/${projectId}/invite_2/genInvite.do`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
   
    /**
     * 1.7排行榜
     * @param callback 回调
     */
    public static rankInfo(callback, projectId){
        let param: any = {
        }
        const net: INetData = {
            name: 'rankInfo',
            uri: `/projectx/${projectId}/join_1/passRankList.do`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.8开启传递 
     * @param callback 回调
     */
    public static doStart(callback, projectId){
        let param: any = {
        }
        const net: INetData = {
            name: 'doStart',
            uri: `/projectx/${projectId}/join_1/join.do`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.9参与火炬传递（是否开启动画）
     * @param callback 回调
     */
    public static accept(callback, projectId,inviteCode){
        let param: any = {
            inviteCode:inviteCode
        }
        const net: INetData = {
            name: 'accept',
            uri: `/projectx/${projectId}/invite_2/accept.do`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    // /**
    //  * 1.10加入队伍
    //  * @param callback 回调
    //  */
    // public static acceptInvite(callback, projectId){
    //     let param: any = {
    //     }
    //     const net: INetData = {
    //         name: 'acceptInvite',
    //         uri: `/projectx/${projectId}/invite_1/accept.do`,
    //         type: 'get',
    //         dataType: 'json',
    //         hideMsg: true,
    //         param: param,
    //         callback: callback
    //     };
    //     NetManager.ins.send(net);
    // }

    public static joinPkTeam(callback, projectId,inviteCode){
        let param: any = {
            inviteCode:inviteCode
        }
        
        const net: INetData = {
            name: 'joinPkTeam',
            uri: `/projectx/${projectId}/invite_2/joinPkTeam.do`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.11分享足迹 
     * @param callback 回调
     */
    public static shareFootprint(callback, projectId, area){
        let param: any = {
            area:area
        }
        const net: INetData = {
            name: 'shareFootprint',
            uri: `/projectx/${projectId}/join_1/shareFootprint.do`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.12传递记录 
     * @param callback 回调
     */
    public static getPassingRecords(callback, projectId){
        let param: any = {
        }
        const net: INetData = {
            name: 'getPassingRecords',
            uri: `/projectx/${projectId}/invite_2/passRecord.do`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.13pk基础信息 
     * @param callback 回调
     */
    public static getPkBaseInfo(callback, projectId){
        let param: any = {
        }
        const net: INetData = {
            name: 'getPkBaseInfo',
            uri: `/projectx/${projectId}/invite_2/getPkBaseInfo.do`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.14邀请-开启传递
     * @param callback 回调
     */
    public static openPass(callback, projectId, shareCode){
        let param: any = {
            shareCode:shareCode
        }
        const net: INetData = {
            name: 'openPass',
            uri: `/projectx/${projectId}/invite_2/openPass.do`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.15足迹分享列表 
     * @param callback 回调
     */
    public static shareFootprintList(callback, projectId){
        let param: any = {
        }
        const net: INetData = {
            name: 'shareFootprintList',
            uri: `/projectx/${projectId}/join_1/shareFootprintList.do`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param: param,
            callback: callback
        };
        NetManager.ins.send(net);
    }
    /**
     * 1.16 base64上传图片 
     * @param callback 回调
     */
    public static imgUrl(callback, img64){
        let param: any = {
            img64:img64
        }
        
        
        const net: INetData = {
            name: 'imgUrl',
            uri: `/customActivity/duiba/imgUrl`,
            type: 'post',
            dataType: 'json',
            hideMsg: true,
            param:JSON.stringify(param),
            callback: callback
        };
        NetManager.ins.send(net);
    }

    /**
     * 1.17 获取带参二维码里面的内容，用于自己生成二维码 
     * @param callback 回调
     */
    public static getSceneQrCodeContent(callback, sceneId){
        let param: any = {
            sceneId:sceneId
        }
        
        
        const net: INetData = {
            name: 'getSceneQrCodeContent',
            uri: `/wechat/sceneqrcode/getSceneQrCodeContent`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param:param,
            callback: callback
        };
        NetManager.ins.send(net);
    }

    /**
     * 1.18 获取二维码
     * @param callback 回调
     */
    public static getQrcode(callback, content,width,height){
        let param: any = {
            content:content,
            width:width,
            height:height
        }
        
        
        const net: INetData = {
            name: 'getQrcode',
            uri: `/customActivity/qrcode/getQrcode`,
            type: 'get',
            dataType: 'json',
            hideMsg: true,
            param:param,
            callback: callback
        };
        NetManager.ins.send(net);
    }

    /**
     * 1.19 保存弹窗状态
     * @param callback 回调
     */
    public static savePopupState(callback, projectId, type){
        let param: any = {
            type:type
        }
    
        const net: INetData = {
            name: 'savePopupState',
            uri: `/projectx/${projectId}/join_1/savePopupState.do`,
            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: DataManager.ins.customCfgData.hdToolId,
                activityId: DataManager.ins.customCfgData.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: activityId,
            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);
    }

    /**
     * 轮询开始状态
     * @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);
    }
}