package emu.nebula.server.handlers;

import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId;
import emu.nebula.proto.PlayerFormation.PlayerFormationReq;
import emu.nebula.net.HandlerId;
import emu.nebula.net.GameSession;

@HandlerId(NetMsgId.player_formation_req)
public class HandlerPlayerFormationReq extends NetHandler {

    @Override
    public byte[] handle(GameSession session, byte[] message) throws Exception {
        var req = PlayerFormationReq.parseFrom(message);
        
        boolean success = session.getPlayer().getFormations().updateFormation(req.getFormation());
        
        return session.encodeMsg(success ? NetMsgId.player_formation_succeed_ack : NetMsgId.player_formation_failed_ack);
    }

}
