/*
 * This file is a part of the SteamWar software.
 *
 * Copyright (C) 2022  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.slaves.laufbau.boundingboxes;

import de.steamwar.bausystem.features.slaves.laufbau.BlockBoundingBox;
import de.steamwar.bausystem.features.slaves.laufbau.BoundingBoxLoader;
import de.steamwar.bausystem.features.slaves.laufbau.Cuboid;
import de.steamwar.core.Core;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.type.Fence;
import org.bukkit.block.data.type.Wall;

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

import static de.steamwar.bausystem.features.slaves.laufbau.LaufbauUtils.createItem;
import static de.steamwar.bausystem.features.slaves.laufbau.LaufbauUtils.pixelCuboid;

@Linked
public class WallBoundingBox implements BoundingBoxLoader {

    @Override
    public void load() {
        if (Core.getVersion() > 15) {
            v18();
        } else {
            v15();
        }
    }

    private void v18() {
        for (int nx = 0; nx < 2; nx++) {
            for (int nz = 0; nz < 2; nz++) {
                for (int px = 0; px < 2; px++) {
                    for (int pz = 0; pz < 2; pz++) {
                        Wall fence = (Wall) Material.END_STONE_BRICK_WALL.createBlockData();
                        List<String> lore = new ArrayList<>();
                        List<Cuboid> cuboidList = new ArrayList<>();
                        cuboidList.add(pixelCuboid(4, 0, 4, 8, 24, 8));
                        if (nz == 1) {
                            lore.add("LAUFBAU_CONNECTION_NORTH");
                            fence.setHeight(BlockFace.NORTH, Wall.Height.LOW);
                            cuboidList.add(pixelCuboid(5, 0, 0, 6, 24, 4));
                        }
                        if (pz == 1) {
                            lore.add("LAUFBAU_CONNECTION_SOUTH");
                            fence.setHeight(BlockFace.SOUTH, Wall.Height.LOW);
                            cuboidList.add(pixelCuboid(5, 0, 12, 6, 24, 4));
                        }
                        if (nx == 1) {
                            lore.add("LAUFBAU_CONNECTION_WEST");
                            fence.setHeight(BlockFace.WEST, Wall.Height.LOW);
                            cuboidList.add(pixelCuboid(0, 0, 5, 4, 24, 6));
                        }
                        if (px == 1) {
                            lore.add("LAUFBAU_CONNECTION_EAST");
                            fence.setHeight(BlockFace.EAST, Wall.Height.LOW);
                            cuboidList.add(pixelCuboid(12, 0, 5, 4, 24, 6));
                        }
                        new BlockBoundingBox(fence, cuboidList, createItem("LAUFBAU_BLOCK_END_STONE_BRICK_WALL", Material.END_STONE_BRICK_WALL, lore.toArray(new String[0])));
                    }
                }
            }
        }
    }

    private void v15() {
        for (int nx = 0; nx < 2; nx++) {
            for (int nz = 0; nz < 2; nz++) {
                for (int px = 0; px < 2; px++) {
                    for (int pz = 0; pz < 2; pz++) {
                        Fence fence = (Fence) Material.END_STONE_BRICK_WALL.createBlockData();
                        List<String> lore = new ArrayList<>();
                        List<Cuboid> cuboidList = new ArrayList<>();
                        cuboidList.add(pixelCuboid(4, 0, 4, 8, 24, 8));
                        if (nz == 1) {
                            lore.add("LAUFBAU_CONNECTION_NORTH");
                            fence.setFace(BlockFace.NORTH, true);
                            cuboidList.add(pixelCuboid(5, 0, 0, 6, 24, 4));
                        }
                        if (pz == 1) {
                            lore.add("LAUFBAU_CONNECTION_SOUTH");
                            fence.setFace(BlockFace.SOUTH, true);
                            cuboidList.add(pixelCuboid(5, 0, 12, 6, 24, 4));
                        }
                        if (nx == 1) {
                            lore.add("LAUFBAU_CONNECTION_WEST");
                            fence.setFace(BlockFace.WEST, true);
                            cuboidList.add(pixelCuboid(0, 0, 5, 4, 24, 6));
                        }
                        if (px == 1) {
                            lore.add("LAUFBAU_CONNECTION_EAST");
                            fence.setFace(BlockFace.EAST, true);
                            cuboidList.add(pixelCuboid(12, 0, 5, 4, 24, 6));
                        }
                        new BlockBoundingBox(fence, cuboidList, createItem("LAUFBAU_BLOCK_END_STONE_BRICK_WALL", Material.END_STONE_BRICK_WALL, lore.toArray(new String[0])));
                    }
                }
            }
        }
    }
}
