package emu.nebula.server.handlers;

import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId;
import emu.nebula.proto.Public.UI32;
import emu.nebula.net.HandlerId;
import emu.nebula.Nebula;
import emu.nebula.net.GameSession;

@HandlerId(NetMsgId.tutorial_level_reward_receive_req)
public class HandlerTutorialLevelRewardReceiveReq extends NetHandler {

    @Override
    public byte[] handle(GameSession session, byte[] message) throws Exception {
        // Parse request
        var req = UI32.parseFrom(message);
        
        // Get rewards
        var change = Nebula.getGameContext().getTutorialModule().recvReward(session.getPlayer(), req.getValue());
        
        if (change == null) {
            return session.encodeMsg(NetMsgId.tutorial_level_reward_receive_failed_ack);
        }
        
        // Encode and send
        return session.encodeMsg(NetMsgId.tutorial_level_reward_receive_succeed_ack, change.toProto());
    }

}
