import { ApiCall } from "tsrpc";
import { EquipFun } from '../../public/equip';
import { HeroFun } from '../../public/hero';
import { ReqOneKeyTakeOff, ResOneKeyTakeOff } from "../../shared/protocols/equip/PtlOneKeyTakeOff";
import { EquipShared } from '../../shared/public/equip';
import kfjsFun from "../../public/kaifujingsai";

export default async function (call: ApiCall<ReqOneKeyTakeOff, ResOneKeyTakeOff>) {
    let hero = await HeroFun.getHero(call, call.req.h_id);
    if (!hero) return call.errorCode(-1);

    let obj = hero.equip || {};
    let equips = Object.values(obj).filter(s => !!s).map(s => EquipShared.fmtEquip(s));

    if (equips.length > 0) {
        for (let equip of equips) {
            await EquipFun.changeEquipAttr(call, equip, { wearaId: '' }, false);
        }
        await HeroFun.changeHeroAttr(call, hero, { equip: {} });
    }

    call.succ({});

    kfjsFun.setEquipLvCount(call)

}