package net.minecraft.server.dialog;

import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import java.util.Optional;
import net.minecraft.util.ExtraCodecs;

public record ServerLinksDialog(@Override CommonDialogData common, @Override Optional<ActionButton> exitAction, @Override int columns, int buttonWidth)
    implements ButtonListDialog {
    public static final MapCodec<ServerLinksDialog> MAP_CODEC = RecordCodecBuilder.mapCodec(
        instance -> instance.group(
                CommonDialogData.MAP_CODEC.forGetter(ServerLinksDialog::common),
                ActionButton.CODEC.optionalFieldOf("exit_action").forGetter(ServerLinksDialog::exitAction),
                ExtraCodecs.POSITIVE_INT.optionalFieldOf("columns", 2).forGetter(ServerLinksDialog::columns),
                WIDTH_CODEC.optionalFieldOf("button_width", 150).forGetter(ServerLinksDialog::buttonWidth)
            )
            .apply(instance, ServerLinksDialog::new)
    );

    @Override
    public MapCodec<ServerLinksDialog> codec() {
        return MAP_CODEC;
    }
}
