/*
 *   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.simulator.data;

import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
import de.steamwar.bausystem.features.simulator.execute.SimulatorStabGenerator;
import de.steamwar.inventory.InvCallback;
import de.steamwar.inventory.SWItem;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.bukkit.Material;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer;

@Getter
@Setter
@RequiredArgsConstructor
public final class Simulator {
    private SimulatorStabGenerator stabGenerator = null;
    private Material material = Material.BARREL;
    private final String name;
    private final List<SimulatorGroup> groups = new ArrayList<>();

    private boolean autoTrace = false;
    private boolean autoTestblock = false;

    public void move(int x, int y, int z) {
        groups.forEach(simulatorGroup -> {
            simulatorGroup.move(x, y, z);
        });
    }

    public SWItem toItem(Player player, InvCallback invCallback) {
        return new SWItem(material, "§e" + name, invCallback);
    }

    public void toSimulatorActions(BiConsumer<Integer, SimulatorAction> tickStart, BiConsumer<Integer, SimulatorAction> tickEnd) {
        groups.forEach(simulatorGroup -> {
            simulatorGroup.toSimulatorActions(tickStart, tickEnd);
        });
    }

    public Simulator add(SimulatorGroup group) {
        groups.add(group);
        return this;
    }
}
