import { GOnHookPets } from "../../../extensions/ngame/assets/ngame/message/proto";
import { app } from "../App";
import { PlayerPetOV, RData, RProto } from "./API";
import { GActionType } from "./GActionType";

export interface ModeHookInfo{
    maps:{[key:number]:number};         //地图关卡信息 {地图Id: 地图关卡Id}
    mapStates:{[key:number]:number};    //地图关卡状态 {地图Id: 战胜次数}
}
export interface ModeOnHookOV{

    playerId:number;        //玩家Id
    onHookMap:number;       //当前玩家所在的地图(配置表Id)
    levelId:number;         //当前关卡Id
    hookInfo:ModeHookInfo;  //关卡信息

}

export interface Dungeon{
    dungeonId:number;                     //副本唯一Id
    playerId:number;                      //副本玩家Id
    dungeonCfgId:number;                  //副本配置表Id
    dungeonCfgItemId:number;              //副本进度表Id
}


export const GAPI = {

    /************** 无限模式接口 ********************/
    //获取模式信息
    GOnHookInfo : async () => RData(await app.api.get(`/game/mode/onHook/info`)) as ModeOnHookOV,
    //切换地图
    GOnHookSetMap : async (mapId,saves:string[]) => RData(await app.api.post(`/game/mode/onHook/setMapId/${mapId}`,saves)) as ModeOnHookOV,
    //生成野怪
    GOnHookSpawnCreeps : async () => RProto(await app.api.get(`/game/mode/onHook/onSpawnCreeps`,{responseType:'arraybuffer'},false),GActionType.GOnHookPets) as GOnHookPets,
    //捕捉野怪
    GOnHookCatchCreeps : async (creepId) => RData(await app.api.post(`/game/mode/onHook/onCatchCreeps/${creepId}`),true) as boolean,
    //出售野怪
    GOnHookSellCreeps : async (creepId) => RData(await app.api.post(`/game/mode/onHook/onSellCreeps/${creepId}`),true) as boolean,
    //下一关
    GOnHookNextLevel : async (saves:string[]) => RData(await app.api.post(`/game/mode/onHook/nextLevel`,saves),true) as ModeOnHookOV,
    //战胜当前关卡
    GOnHookWinLevel : async () => RData(await app.api.post(`/game/mode/onHook/winLevel`),false) as ModeOnHookOV,

    /*************** 副本接口 ***********************/
    //获取副本信息
    GDungeonGetInfo : async () => RData(await app.api.get(`/game/mode/dungeon/info`)) as {[key:string]:Dungeon},
    //消耗钥匙挑战副本
    GDungeonChallenge : async (dungeonId,dungeonItemId) => RData(await app.api.post(`/game/mode/dungeon/challenge/dungeon/${dungeonId}/${dungeonItemId}`),false) as {[key:string]:Dungeon},

}