/*
 *   This file is a part of the SteamWar software.
 *
 *   Copyright (C) 2025 SteamWar.de-Serverteam
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *   GNU Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package de.steamwar.bausystem.features.loadtimer;

import de.steamwar.bausystem.region.Region;
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;

@Linked
public class LoadtimerCommand extends SWCommand {
    public LoadtimerCommand() {
        super("loadtimer", "lt", "stopuhr");
        addDefaultHelpMessage("LOADTIMER_HELP_OVERVIEW");
    }

    @Register(value = "start", description = "LOADTIMER_HELP_START_1")
    public void start(@Validator Player p) {
        start(p, TimerMode.HALF);
    }

    @Register(value = "start", description = {"LOADTIMER_HELP_START_2", "LOADTIMER_HELP_START_3"})
    public void start(@Validator Player p, TimerMode mode) {
        Region r = Region.getRegion(p.getLocation());
        if (r.getType().isGlobal()) return;
        if (!Loadtimer.hasTimer(r)) {
            Loadtimer.createLoadtimer(r, mode == TimerMode.HALF);
        }
    }

    @Register(value = "stop", description = "LOADTIMER_HELP_STOP")
    public void stop(@Validator Player p) {
        Region r = Region.getRegion(p.getLocation());
        if (r.getType().isGlobal()) return;
        if (Loadtimer.hasTimer(r)) {
            Loadtimer.getTimer(r).delete();
        }
    }

    public enum TimerMode {
        FULL,
        HALF
    }
}
