package de.teleportsuite.managers;

import de.teleportsuite.TeleportSuite;
import de.teleportsuite.models.TeleportLocation;
import de.teleportsuite.models.Warp;
import org.bukkit.entity.Player;
import java.util.List;

public class WarpManager {
    private final TeleportSuite plugin;
    public WarpManager(TeleportSuite plugin) { this.plugin = plugin; }

    public void setWarp(Player player, String name, String permission) {
        TeleportLocation loc = new TeleportLocation(player.getLocation(), plugin.getConfigManager().getServerName());
        plugin.getDatabaseManager().saveWarp(name, loc, player.getUniqueId(), permission);
        player.sendMessage(plugin.getConfigManager().getMessage("warp-set", "name", name));
    }

    public void teleportWarp(Player player, String name) {
        Warp warp = plugin.getDatabaseManager().getWarp(name);
        if (warp == null) {
            player.sendMessage(plugin.getConfigManager().getMessage("warp-not-found", "name", name));
            return;
        }
        if (warp.getPermission() != null && !player.hasPermission(warp.getPermission())) {
            player.sendMessage(plugin.getConfigManager().getMessage("no-permission"));
            return;
        }
        plugin.getTeleportManager().teleport(player, warp.getLocation());
    }

    public boolean deleteWarp(String name) {
        return plugin.getDatabaseManager().deleteWarp(name);
    }

    public List<Warp> getAllWarps() {
        return plugin.getDatabaseManager().getAllWarps();
    }
}
