/*
 *   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.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.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.FaceAttachable;
import org.bukkit.block.data.type.Grindstone;

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 GrindstoneBoundingBox implements BoundingBoxLoader {

    @Override
    public void load() {
        floorNorthGrindstone();
        floorEastGrindstone();

        ceilingNorthGrindstone();
        ceilingEastGrindstone();

        wallNorthGrindstone();
        wallSouthGrindstone();
        wallEastGrindstone();
        wallWestGrindstone();
    }

    public void floorNorthGrindstone() {
        Grindstone grindstone = (Grindstone) Material.GRINDSTONE.createBlockData();
        grindstone.setAttachedFace(FaceAttachable.AttachedFace.FLOOR);
        grindstone.setFacing(BlockFace.NORTH);
        List<Cuboid> cuboidList = new ArrayList<>();
        cuboidList.add(pixelCuboid(4, 4, 2, 8, 12, 12));
        cuboidList.add(pixelCuboid(2, 0, 6, 2, 7, 4));
        cuboidList.add(pixelCuboid(12, 0, 6, 2, 7, 4));
        cuboidList.add(pixelCuboid(2, 7, 5, 2, 6, 6));
        cuboidList.add(pixelCuboid(12, 7, 5, 2, 6, 6));
        new BlockBoundingBox(grindstone, cuboidList, createItem("LAUFBAU_BLOCK_GRINDSTONE", Material.GRINDSTONE, "LAUFBAU_ATTACHMENT_FLOOR", "LAUFBAU_FACING_NORTH", "LAUFBAU_FACING_SOUTH"));
    }

    public void floorEastGrindstone() {
        Grindstone grindstone = (Grindstone) Material.GRINDSTONE.createBlockData();
        grindstone.setAttachedFace(FaceAttachable.AttachedFace.FLOOR);
        grindstone.setFacing(BlockFace.EAST);
        List<Cuboid> cuboidList = new ArrayList<>();
        cuboidList.add(pixelCuboid(2, 4, 4, 12, 12, 8));
        cuboidList.add(pixelCuboid(6, 0, 2, 4, 7, 2));
        cuboidList.add(pixelCuboid(6, 0, 12, 4, 7, 2));
        cuboidList.add(pixelCuboid(5, 7, 2, 6, 6, 2));
        cuboidList.add(pixelCuboid(5, 7, 12, 6, 6, 2));
        new BlockBoundingBox(grindstone, cuboidList, createItem("LAUFBAU_BLOCK_GRINDSTONE", Material.GRINDSTONE, "LAUFBAU_ATTACHMENT_FLOOR", "LAUFBAU_FACING_EAST", "LAUFBAU_FACING_WEST"));
    }

    public void ceilingNorthGrindstone() {
        Grindstone grindstone = (Grindstone) Material.GRINDSTONE.createBlockData();
        grindstone.setAttachedFace(FaceAttachable.AttachedFace.CEILING);
        grindstone.setFacing(BlockFace.NORTH);
        List<Cuboid> cuboidList = new ArrayList<>();
        cuboidList.add(pixelCuboid(4, 0, 2, 8, 12, 12));
        cuboidList.add(pixelCuboid(2, 9, 6, 2, 7, 4));
        cuboidList.add(pixelCuboid(12, 9, 6, 2, 7, 4));
        cuboidList.add(pixelCuboid(2, 3, 5, 2, 6, 6));
        cuboidList.add(pixelCuboid(12, 3, 5, 2, 6, 6));
        new BlockBoundingBox(grindstone, cuboidList, createItem("LAUFBAU_BLOCK_GRINDSTONE", Material.GRINDSTONE, "LAUFBAU_ATTACHMENT_CEILING", "LAUFBAU_FACING_NORTH", "LAUFBAU_FACING_SOUTH"));
    }

    public void ceilingEastGrindstone() {
        Grindstone grindstone = (Grindstone) Material.GRINDSTONE.createBlockData();
        grindstone.setAttachedFace(FaceAttachable.AttachedFace.CEILING);
        grindstone.setFacing(BlockFace.EAST);
        List<Cuboid> cuboidList = new ArrayList<>();
        cuboidList.add(pixelCuboid(2, 0, 4, 12, 12, 8));
        cuboidList.add(pixelCuboid(6, 9, 2, 4, 7, 2));
        cuboidList.add(pixelCuboid(6, 9, 12, 4, 7, 2));
        cuboidList.add(pixelCuboid(5, 3, 2, 6, 6, 2));
        cuboidList.add(pixelCuboid(5, 3, 12, 6, 6, 2));
        new BlockBoundingBox(grindstone, cuboidList, createItem("LAUFBAU_BLOCK_GRINDSTONE", Material.GRINDSTONE, "LAUFBAU_ATTACHMENT_CEILING", "LAUFBAU_FACING_EAST", "LAUFBAU_FACING_WEST"));
    }

    public void wallNorthGrindstone() {
        Grindstone grindstone = (Grindstone) Material.GRINDSTONE.createBlockData();
        grindstone.setAttachedFace(FaceAttachable.AttachedFace.WALL);
        grindstone.setFacing(BlockFace.NORTH);
        List<Cuboid> cuboidList = new ArrayList<>();
        cuboidList.add(pixelCuboid(4, 2, 0, 8, 12, 12));
        cuboidList.add(pixelCuboid(2, 6, 9, 2, 4, 7));
        cuboidList.add(pixelCuboid(12, 6, 9, 2, 4, 7));
        cuboidList.add(pixelCuboid(2, 5, 3, 2, 6, 6));
        cuboidList.add(pixelCuboid(12, 5, 3, 2, 6, 6));
        new BlockBoundingBox(grindstone, cuboidList, createItem("LAUFBAU_BLOCK_GRINDSTONE", Material.GRINDSTONE, "LAUFBAU_ATTACHMENT_WALL", "LAUFBAU_FACING_NORTH"));
    }

    public void wallSouthGrindstone() {
        Grindstone grindstone = (Grindstone) Material.GRINDSTONE.createBlockData();
        grindstone.setAttachedFace(FaceAttachable.AttachedFace.WALL);
        grindstone.setFacing(BlockFace.SOUTH);
        List<Cuboid> cuboidList = new ArrayList<>();
        cuboidList.add(pixelCuboid(4, 2, 4, 8, 12, 12));
        cuboidList.add(pixelCuboid(2, 6, 0, 2, 4, 7));
        cuboidList.add(pixelCuboid(12, 6, 0, 2, 4, 7));
        cuboidList.add(pixelCuboid(2, 5, 7, 2, 6, 6));
        cuboidList.add(pixelCuboid(12, 5, 7, 2, 6, 6));
        new BlockBoundingBox(grindstone, cuboidList, createItem("LAUFBAU_BLOCK_GRINDSTONE", Material.GRINDSTONE, "LAUFBAU_ATTACHMENT_WALL", "LAUFBAU_FACING_SOUTH"));
    }

    public void wallEastGrindstone() {
        Grindstone grindstone = (Grindstone) Material.GRINDSTONE.createBlockData();
        grindstone.setAttachedFace(FaceAttachable.AttachedFace.WALL);
        grindstone.setFacing(BlockFace.EAST);
        List<Cuboid> cuboidList = new ArrayList<>();
        cuboidList.add(pixelCuboid(4, 2, 4, 12, 12, 8));
        cuboidList.add(pixelCuboid(0, 6, 2, 7, 4, 2));
        cuboidList.add(pixelCuboid(0, 6, 12, 7, 4, 2));
        cuboidList.add(pixelCuboid(7, 5, 2, 6, 6, 2));
        cuboidList.add(pixelCuboid(7, 5, 12, 6, 6, 2));
        new BlockBoundingBox(grindstone, cuboidList, createItem("LAUFBAU_BLOCK_GRINDSTONE", Material.GRINDSTONE, "LAUFBAU_ATTACHMENT_WALL", "LAUFBAU_FACING_EAST"));
    }

    public void wallWestGrindstone() {
        Grindstone grindstone = (Grindstone) Material.GRINDSTONE.createBlockData();
        grindstone.setAttachedFace(FaceAttachable.AttachedFace.WALL);
        grindstone.setFacing(BlockFace.WEST);
        List<Cuboid> cuboidList = new ArrayList<>();
        cuboidList.add(pixelCuboid(0, 2, 4, 12, 12, 8));
        cuboidList.add(pixelCuboid(9, 6, 2, 7, 4, 2));
        cuboidList.add(pixelCuboid(9, 6, 12, 7, 4, 2));
        cuboidList.add(pixelCuboid(3, 5, 2, 6, 6, 2));
        cuboidList.add(pixelCuboid(3, 5, 12, 6, 6, 2));
        new BlockBoundingBox(grindstone, cuboidList, createItem("LAUFBAU_BLOCK_GRINDSTONE", Material.GRINDSTONE, "LAUFBAU_ATTACHMENT_WALL", "LAUFBAU_FACING_WEST"));
    }
}
