import { ApiCall } from "tsrpc";
import { HeroFun } from '../../public/hero';
import { PlayerFun } from '../../public/player';
import { ReqAwake, ResAwake } from "../../shared/protocols/hero/PtlAwake";

export default async function (call: ApiCall<ReqAwake, ResAwake>) {
    let hero = await HeroFun.getHero(call, call.req._id)
    if (!hero) return call.error('', { code: -1 });

    let awake = hero.awake || 0;
    let conf = G.gc.hero_jx[awake + 1];
    if (!conf) return call.error('', { code: -2 });

    let need = [].concat(...conf.item_cos, { a: 'item', t: hero.heroId, n: conf.HeroDebris_Cos });
    await PlayerFun.checkNeedIsMeet(call, need);
    await PlayerFun.cutNeed(call, need);

    await HeroFun.changeHeroAttr(call, hero, {awake: awake + 1});

    call.succ({});
}