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 sm) {
        this.action = a;
        this.tab = sm;
    }
    
    public static ServerboundSeenAdvancementsPacket openedTab(final Advancement u) {
        return new ServerboundSeenAdvancementsPacket(Action.OPENED_TAB, u.getId());
    }
    
    public static ServerboundSeenAdvancementsPacket closedScreen() {
        return new ServerboundSeenAdvancementsPacket(Action.CLOSED_SCREEN, null);
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.action = kv.<Action>readEnum(Action.class);
        if (this.action == Action.OPENED_TAB) {
            this.tab = kv.readResourceLocation();
        }
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeEnum(this.action);
        if (this.action == Action.OPENED_TAB) {
            kv.writeResourceLocation(this.tab);
        }
    }
    
    @Override
    public void handle(final ServerGamePacketListener pl) {
        pl.handleSeenAdvancements(this);
    }
    
    public Action getAction() {
        return this.action;
    }
    
    public ResourceLocation getTab() {
        return this.tab;
    }
    
    public enum Action {
        OPENED_TAB, 
        CLOSED_SCREEN;
    }
}
