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 TallMirrorShape implements IMirrorShape {
    public static final VoxelShape FOOT_SHAPE_NORTH = Block.box(0, 0, 0, 16, 16, 1.1),
            FOOT_SHAPE_SOUTH , FOOT_SHAPE_EAST, FOOT_SHAPE_WEST,
            HEAD_SHAPE_NORTH= Block.box(0, 0, 0, 16, 16, 1.1),
            HEAD_SHAPE_SOUTH, HEAD_SHAPE_EAST, HEAD_SHAPE_WEST;
    static {
        FOOT_SHAPE_EAST = ShapeUtil.RotateVoxelShapeClockwise(FOOT_SHAPE_NORTH);
        FOOT_SHAPE_SOUTH = ShapeUtil.RotateVoxelShapeClockwise(FOOT_SHAPE_EAST);
        FOOT_SHAPE_WEST = ShapeUtil.RotateVoxelShapeClockwise(FOOT_SHAPE_SOUTH);

        HEAD_SHAPE_EAST = ShapeUtil.RotateVoxelShapeClockwise(HEAD_SHAPE_NORTH);
        HEAD_SHAPE_SOUTH = ShapeUtil.RotateVoxelShapeClockwise(HEAD_SHAPE_EAST);
        HEAD_SHAPE_WEST = ShapeUtil.RotateVoxelShapeClockwise(HEAD_SHAPE_SOUTH);
    }
    @Override
    public VoxelShape getDefaultShape(Direction direction) {
        return (VoxelShape) switch (direction) {
            case DOWN, UP -> Stream.empty();
            case NORTH -> FOOT_SHAPE_NORTH;
            case SOUTH -> FOOT_SHAPE_SOUTH;
            case WEST -> FOOT_SHAPE_WEST;
            case EAST -> FOOT_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) return getDefaultShape(direction);
        else return (VoxelShape) switch (direction) {
            case DOWN, UP -> Stream.empty();
            case NORTH -> HEAD_SHAPE_NORTH;
            case SOUTH -> HEAD_SHAPE_SOUTH;
            case WEST -> HEAD_SHAPE_WEST;
            case EAST -> HEAD_SHAPE_EAST;
        };
    }

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