/*
 *   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.shieldprinting.impl;

import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.shieldprinting.BlockDataConfiguration;
import de.steamwar.inventory.SWItem;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.type.Wall;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.List;

public class WallConfiguration implements BlockDataConfiguration<Wall> {

    private Material material;
    private State state;

    public WallConfiguration(Material material) {
        this.material = material;
        this.state = State.FROM_ORIGINAL;
    }

    @Override
    public void previous() {
        switch (state) {
            case FROM_ORIGINAL:
                state = State.FROM_COPY;
                break;
            case FROM_COPY:
                state = State.FROM_ORIGINAL;
                break;
        }
    }

    @Override
    public void next() {
        previous();
    }

    @Override
    public SWItem get(Player player) {
        SWItem swItem = new SWItem(material, BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_WALL", player, material.name()));
        List<String> lore = new ArrayList<>();
        for (State value : State.values()) {
            lore.add(BauSystem.MESSAGE.parse((value == state) ? "SHIELD_PRINTING_GUI_STATE_ACTIVE" : "SHIELD_PRINTING_GUI_STATE_INACTIVE",
                    player, BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_" + value.name(), player)));
        }
        lore.add("");
        lore.add(BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_PREVIOUS", player));
        lore.add(BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_NEXT", player));
        swItem.setLore(lore);
        return swItem;
    }

    @Override
    public void apply(Wall copied, Wall worldOriginal) {
        switch (state) {
            case FROM_ORIGINAL:
                copied.setUp(worldOriginal.isUp());
                copied.setHeight(BlockFace.NORTH, worldOriginal.getHeight(BlockFace.NORTH));
                copied.setHeight(BlockFace.EAST, worldOriginal.getHeight(BlockFace.EAST));
                copied.setHeight(BlockFace.SOUTH, worldOriginal.getHeight(BlockFace.SOUTH));
                copied.setHeight(BlockFace.WEST, worldOriginal.getHeight(BlockFace.WEST));
                break;
            case FROM_COPY:
                break;
        }
    }

    private enum State {
        FROM_COPY,
        FROM_ORIGINAL
    }
}
