package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.advancements.Advancement;
import javax.annotation.Nullable;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.network.protocol.Packet;

public class ServerboundSeenAdvancementsPacket implements Packet<ServerGamePacketListener> {
    private Action action;
    private ResourceLocation tab;
    
    public ServerboundSeenAdvancementsPacket() {
    }
    
    public ServerboundSeenAdvancementsPacket(final Action a, @Nullable final ResourceLocation uh) {
        this.action = a;
        this.tab = uh;
    }
    
    public static ServerboundSeenAdvancementsPacket openedTab(final Advancement w) {
        return new ServerboundSeenAdvancementsPacket(Action.OPENED_TAB, w.getId());
    }
    
    public static ServerboundSeenAdvancementsPacket closedScreen() {
        return new ServerboundSeenAdvancementsPacket(Action.CLOSED_SCREEN, null);
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        this.action = mg.<Action>readEnum(Action.class);
        if (this.action == Action.OPENED_TAB) {
            this.tab = mg.readResourceLocation();
        }
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeEnum(this.action);
        if (this.action == Action.OPENED_TAB) {
            mg.writeResourceLocation(this.tab);
        }
    }
    
    @Override
    public void handle(final ServerGamePacketListener qz) {
        qz.handleSeenAdvancements(this);
    }
    
    public Action getAction() {
        return this.action;
    }
    
    public ResourceLocation getTab() {
        return this.tab;
    }
    
    public enum Action {
        OPENED_TAB, 
        CLOSED_SCREEN;
    }
}
