import { NetManager } from "../libs/tw/manager/NetManager";
import { DataManager } from "../libs/tw/manager/DataManager";
import { NetName } from "../libs/tw/enum/NetName";


export class NetPromise {
    private static instance: NetPromise;

    public static get ins(): NetPromise {
        if (!this.instance) {
            this.instance = new NetPromise();
        }
        return this.instance;
    }

    constructor() {}

    /**
     * 查询宠物信息
     */
    getPetInfoKuwo(){
		return new Promise((resolve,reject)=>{
			NetManager.ins.getPetInfoKuwo((success)=>{
				if(!success){
                    reject(success)
				}
				resolve(success)
			},window["CFG"].activityId)
		})
    }

    /**
     * 宠物交互
     * @param petId 
     * @param type 
     */
    petInteractionKuwo(petId,type){
        return new Promise((resolve,reject)=>{
            NetManager.ins.petInteractionKuwo((success)=>{
                if(!success){
                    reject(success)
                }
                resolve(success)
            },petId,type,window["signId"])
        })
    }

    /**
     * 查询签到信息
     * @param signActivityId 
     */
    getSignInfo(signActivityId){
        return new Promise((resolve,reject)=>{
            NetManager.ins.getSignInfo((success)=>{
                if(!success){
                    reject(success)
                }
                resolve(success)
            },signActivityId)
        })
    }

    /**
     * 签到
     * @param signActivityId 
     */
    doSign(signActivityId){
        return new Promise((resolve,reject)=>{
            NetManager.ins.doSign((success)=>{
                if(!success){
                    reject(success)
                }
                resolve(success)
            },signActivityId)
        })
    }

     /**
     * 获取任务
     * @param signActivityId 
     */
    getTaskInfoKuwo(eduSignId,petId){
        return new Promise((resolve,reject)=>{
            NetManager.ins.getTaskInfoKuwo((success)=>{
                if(!success){
                    reject(success)
                }
                resolve(success)
            },eduSignId,petId)
        })
    }

    /**
     * 成就墙
     * @param signActivityId 
     */
    getEvolutionRecordKuwo(eduSignId,petId){
        return new Promise((resolve,reject)=>{
            NetManager.ins.getEvolutionRecordKuwo((success)=>{
                if(!success){
                    reject(success)
                }
                resolve(success)
            },eduSignId,petId)
        })
    }

    /**
     * 获取乐谱
     * @param signActivityId 
     */
    getKuwoMusicScoreKuwo(eduSignId,pageSize,pageNo){
        return new Promise((resolve,reject)=>{
            NetManager.ins.getKuwoMusicScoreKuwo((success)=>{
                if(!success){
                    reject(success)
                }
                resolve(success)
            },eduSignId,pageSize,pageNo)
        })
    }

    /**
     * 获取音乐学习成果接口
     * @param signActivityId 
     */
    getLearnMusicHarvestKuwo(petId,eduSignId,loginUid,sid){
        return new Promise((resolve,reject)=>{
            NetManager.ins.getLearnMusicHarvestKuwo((success)=>{
                if(!success){
                    reject(success)
                }
                resolve(success)
            },petId,eduSignId,loginUid,sid)
        })
    }

     /**
     * 完成任务成果接口
     * @param signActivityId 
     */
    completeTaskKuwo(eduSignId,type){
        return new Promise((resolve,reject)=>{
            NetManager.ins.completeTaskKuwo((success)=>{
                if(!success){
                    reject(success)
                }
                resolve(success)
            },eduSignId,type)
        })
    }

    /**
     * 待收藏歌曲列表接口
     * @param loginUid 
     * @param sid 
     */
    forFavor(loginUid,sid){
        return new Promise((resolve,reject)=>{
            NetManager.ins.forFavor((success)=>{
                let data=DataManager.ins.getData(NetName.FORFAVOR_KUWO)
                if(data.msg!="success"){
                    reject(success)
                }
                resolve(success)
            },loginUid,sid)
        })
    }

     /**
     * 收藏歌曲列表接口
     * @param loginUid 
     * @param sid 
     */
    likeSong(loginUid,sid,mid){
        return new Promise((resolve,reject)=>{
            NetManager.ins.likeSong((success)=>{
                let data=DataManager.ins.getData(NetName.LIKESONG_KUWO)
                if(data.msg!="success"){
                    reject(success)
                }
                resolve(success)
            },loginUid,sid,mid)
        })
    }

    /**
     * 分享功能
     */
    handleShare() {
        return new Promise((resolve,reject)=>{
            window["kuwoApi"].share({
            imgurl:"https://yun.duiba.com.cn/refactor/pc/assest/225_140.png",
            imageurl:"https://yun.duiba.com.cn/refactor/pc/assest/225_140.png",
            url: "http://m.kuwo.cn",
            weibo: '微博测试',
            qqspace: 'qq空间测试',
            qqspaceTitle: 'qq空间标题',
            qqfriend: 'qq好友分享描述测试',
            qqfriendTitle: 'qq好友标题',
            wxmsg: '微信分享描述',
            wxdes: '微信分享信息',
            needconfirm: '0',
            callback: function(res) {
                resolve()
            }
            });
        })
    };

    /**
     * 播放音乐
     * @param data 
     */
    handlePlay(data) {
        window["kuwoApi"].play({
          index: 0,
          isplayall: false,
          libpath: "worldcup",
          listpic: "",
          listtitle: "",
          musiclist: [data],
          callback: (res)=>{
            console.log('play', res);
          }
        });
      }
}