// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.server.core.prefab.selection.mask;

import com.hypixel.hytale.math.vector.Vector3i;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.universe.world.accessor.ChunkAccessor;

public class MultiBlockMask extends BlockMask
{
    private static final String BLOCK_MASK_SEPARATOR = ";";
    private final BlockMask[] masks;
    
    public MultiBlockMask(final BlockMask[] masks) {
        super(BlockFilter.EMPTY_ARRAY);
        this.masks = masks;
    }
    
    @Override
    public boolean isExcluded(@Nonnull final ChunkAccessor accessor, final int x, final int y, final int z, final Vector3i min, final Vector3i max, final int blockId) {
        return this.isExcluded(accessor, x, y, z, min, max, blockId, -1);
    }
    
    @Override
    public boolean isExcluded(@Nonnull final ChunkAccessor accessor, final int x, final int y, final int z, final Vector3i min, final Vector3i max, final int blockId, final int fluidId) {
        boolean excluded = false;
        for (final BlockMask mask : this.masks) {
            if (mask.isExcluded(accessor, x, y, z, min, max, blockId, fluidId)) {
                excluded = true;
                break;
            }
        }
        return this.isInverted() != excluded;
    }
    
    @Nonnull
    @Override
    public String toString() {
        if (this.masks.length == 0) {
            return "-";
        }
        final String base = BlockMask.joinElements(";", this.masks);
        return this.isInverted() ? ("!" + base) : base;
    }
    
    @Nonnull
    @Override
    public String informativeToString() {
        if (this.masks.length == 0) {
            return "-";
        }
        final StringBuilder builder = new StringBuilder();
        if (this.isInverted()) {
            builder.append("NOT(");
        }
        for (int i = 0; i < this.masks.length; ++i) {
            final BlockMask mask = this.masks[i];
            builder.append(mask.informativeToString());
            if (i != this.masks.length - 1) {
                builder.append(" AND ");
            }
        }
        if (this.isInverted()) {
            builder.append(")");
        }
        return builder.toString();
    }
}
