package net.thenextlvl.worlds.event;

import net.thenextlvl.worlds.Backup;
import org.bukkit.World;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.world.WorldEvent;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;

/**
 * Represents an event triggered when a {@link World} backup is restored.
 * This event allows developers to perform custom logic before
 * the existing world is removed and the backup is restored.
 *
 * @see WorldActionScheduledEvent
 * @since 4.0.0
 */
public final class WorldBackupRestoreEvent extends WorldEvent implements Cancellable {
    private static final HandlerList handlerList = new HandlerList();

    private boolean cancelled = false;
    private final Backup backup;

    @ApiStatus.Internal
    public WorldBackupRestoreEvent(final World world, final Backup backup) {
        super(world, false);
        this.backup = backup;
    }

    /**
     * Returns the backup being restored.
     *
     * @return the backup being restored
     * @since 4.0.0
     */
    @Contract(pure = true)
    public Backup getBackup() {
        return backup;
    }

    @Override
    @Contract(pure = true)
    public boolean isCancelled() {
        return cancelled;
    }

    @Override
    @Contract(mutates = "this")
    public void setCancelled(final boolean cancel) {
        this.cancelled = cancel;
    }

    @Override
    public HandlerList getHandlers() {
        return handlerList;
    }

    public static HandlerList getHandlerList() {
        return handlerList;
    }
}
