package com.r3944realms.modernlifepatch.content.blocks.type.mirror.shape;

import com.r3944realms.modernlifepatch.content.blocks.type.mirror.MirrorPart;
import com.r3944realms.modernlifepatch.utils.ShapeUtil;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.phys.shapes.VoxelShape;

import java.util.stream.Stream;

public class LargeMirrorShape implements IMirrorShape {
    public static final VoxelShape FOOT_LEFT_SHAPE_NORTH = Block.box(0, 0, 0, 16, 16, 1.1),
            FOOT_LEFT_SHAPE_SOUTH, FOOT_LEFT_SHAPE_WEST, FOOT_LEFT_SHAPE_EAST,
    FOOT_RIGHT_SHAPE_NORTH = Block.box(0, 0, 0, 16, 16, 1.1),
            FOOT_RIGHT_SHAPE_SOUTH, FOOT_RIGHT_SHAPE_WEST, FOOT_RIGHT_SHAPE_EAST,
    HEAD_LEFT_SHAPE_NORTH = Block.box(0, 0, 0, 16, 16, 1.1),
            HEAD_LEFT_SHAPE_SOUTH, HEAD_LEFT_SHAPE_WEST, HEAD_LEFT_SHAPE_EAST,
    HEAD_RIGHT_SHAPE_NORTH = Block.box(0, 0, 0, 16, 16, 1.1),
            HEAD_RIGHT_SHAPE_SOUTH, HEAD_RIGHT_SHAPE_WEST, HEAD_RIGHT_SHAPE_EAST
    ;
    static {
        FOOT_LEFT_SHAPE_EAST = ShapeUtil.RotateVoxelShapeClockwise(FOOT_LEFT_SHAPE_NORTH);
        FOOT_LEFT_SHAPE_SOUTH = ShapeUtil.RotateVoxelShapeClockwise(FOOT_LEFT_SHAPE_EAST);
        FOOT_LEFT_SHAPE_WEST = ShapeUtil.RotateVoxelShapeClockwise(FOOT_LEFT_SHAPE_SOUTH);

        FOOT_RIGHT_SHAPE_EAST = ShapeUtil.RotateVoxelShapeClockwise(FOOT_RIGHT_SHAPE_NORTH);
        FOOT_RIGHT_SHAPE_SOUTH = ShapeUtil.RotateVoxelShapeClockwise(FOOT_RIGHT_SHAPE_EAST);
        FOOT_RIGHT_SHAPE_WEST = ShapeUtil.RotateVoxelShapeClockwise(FOOT_RIGHT_SHAPE_SOUTH);

        HEAD_LEFT_SHAPE_EAST = ShapeUtil.RotateVoxelShapeClockwise(HEAD_LEFT_SHAPE_NORTH);
        HEAD_LEFT_SHAPE_SOUTH = ShapeUtil.RotateVoxelShapeClockwise(HEAD_LEFT_SHAPE_EAST);
        HEAD_LEFT_SHAPE_WEST = ShapeUtil.RotateVoxelShapeClockwise(HEAD_LEFT_SHAPE_SOUTH);

        HEAD_RIGHT_SHAPE_EAST = ShapeUtil.RotateVoxelShapeClockwise(HEAD_RIGHT_SHAPE_NORTH);
        HEAD_RIGHT_SHAPE_SOUTH = ShapeUtil.RotateVoxelShapeClockwise(HEAD_RIGHT_SHAPE_EAST);
        HEAD_RIGHT_SHAPE_WEST = ShapeUtil.RotateVoxelShapeClockwise(HEAD_RIGHT_SHAPE_SOUTH);
    }
    @Override
    public VoxelShape getDefaultShape(Direction direction) {
        return (VoxelShape) switch (direction) {
            case DOWN, UP -> Stream.empty();
            case NORTH -> FOOT_LEFT_SHAPE_NORTH;
            case SOUTH -> FOOT_LEFT_SHAPE_SOUTH;
            case WEST -> FOOT_LEFT_SHAPE_WEST;
            case EAST -> FOOT_LEFT_SHAPE_EAST;
        };
    }

    @Override
    public VoxelShape getShapeByPart(Direction direction, MirrorPart part) {
        if (!testIsRightPart(part)) throw new IllegalArgumentException("Not a right part in mirror shape");
        if (part == MirrorPart.FOOT_LEFT) return getDefaultShape(direction);
        else if (part == MirrorPart.FOOT_RIGHT) return  (VoxelShape) switch (direction) {
            case DOWN, UP -> Stream.empty();
            case NORTH -> FOOT_RIGHT_SHAPE_NORTH;
            case SOUTH -> FOOT_RIGHT_SHAPE_SOUTH;
            case WEST -> FOOT_RIGHT_SHAPE_WEST;
            case EAST -> FOOT_RIGHT_SHAPE_EAST;
        };
        else if (part == MirrorPart.HEAD_LEFT) return  (VoxelShape) switch (direction) {
            case DOWN, UP -> Stream.empty();
            case NORTH -> HEAD_LEFT_SHAPE_NORTH;
            case SOUTH -> HEAD_LEFT_SHAPE_SOUTH;
            case WEST -> HEAD_LEFT_SHAPE_WEST;
            case EAST -> HEAD_LEFT_SHAPE_EAST;
        };
        else return  (VoxelShape) switch (direction) {
            case DOWN, UP -> Stream.empty();
            case NORTH -> HEAD_RIGHT_SHAPE_NORTH;
            case SOUTH -> HEAD_RIGHT_SHAPE_SOUTH;
            case WEST -> HEAD_RIGHT_SHAPE_WEST;
            case EAST -> HEAD_RIGHT_SHAPE_EAST;
        };
    }

    @Override
    public MirrorPart.MirrorType getMirrorType() {
        return MirrorPart.MirrorType.LARGE_MIRROR;
    }
}
