/*
 *  Copyright 2025-2026 R3944Realms
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package top.r3944realms.eroticdungeongame.content.block.multiply;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;

import java.util.Map;

public interface IHasPrimaryPart<T extends Enum<T> & StringRepresentable> {
    EnumProperty<T> getPartProperty();
    /**
     * 获取主部件
     */
    T getPrimaryPart();
    void setPartMap(Map<T, Map<Direction, VoxelShape>> map);

    default BlockEntity createPrimaryBlockEntity(@NotNull BlockPos blockPos, @NotNull BlockState blockState) {
        return null;
    }
    default InteractionResult useOnPrimaryPart(@NotNull BlockState useBlockState, @NotNull Level level,
                                               @NotNull BlockPos primaryBlockPos, @NotNull Player player,
                                               @NotNull InteractionHand hand, @NotNull BlockHitResult hitResult) {
        return InteractionResult.SUCCESS;
    }

    default void removeIfSameBlock(@NotNull Level level, BlockPos pos) {
        BlockState state = level.getBlockState(pos);
        if (state.getBlock() == this) {
            level.removeBlock(pos, false);
        }
    }
    BlockPos[] getAllPartPos(@NotNull Level level, @NotNull BlockPos pos);

    BlockPos getPrimaryPartPos(BlockState blockState, BlockPos blockPos);

    /**
     * 设置为主部件
     */
    default BlockState setPrimaryStatePart(@NotNull BlockState currentState) {
        return setStatePart(currentState, getPrimaryPart());
    }

    /**
     * 设置为部件
     */
    default BlockState setStatePart(@NotNull BlockState currentState, T property) {
        return currentState.setValue(getPartProperty(), property);
    }

    /**
     * 是否是主要部位
     */
    default boolean isPrimary(@NotNull BlockState currentState) {
        return currentState.getValue(getPartProperty()) == getPrimaryPart();
    }


    /**
     * 是否是主要部位
     */
    default boolean isPrimary(@NotNull T part) {
        return part == getPrimaryPart();
    }

}
