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

package com.hypixel.hytale.component;

import javax.annotation.Nullable;
import javax.annotation.Nonnull;
import com.hypixel.hytale.component.system.ISystem;

public class SystemType<ECS_TYPE, T extends ISystem<ECS_TYPE>> implements Comparable<SystemType<ECS_TYPE, ?>>
{
    @Nonnull
    public static final SystemType[] EMPTY_ARRAY;
    @Nonnull
    private final ComponentRegistry<ECS_TYPE> registry;
    @Nonnull
    private final Class<? super T> tClass;
    private final int index;
    private boolean invalidated;
    
    protected SystemType(@Nonnull final ComponentRegistry<ECS_TYPE> registry, @Nonnull final Class<? super T> tClass, final int index) {
        this.registry = registry;
        this.tClass = tClass;
        this.index = index;
    }
    
    @Nonnull
    public ComponentRegistry<ECS_TYPE> getRegistry() {
        return this.registry;
    }
    
    public Class<? super T> getTypeClass() {
        return this.tClass;
    }
    
    public boolean isType(@Nonnull final ISystem<ECS_TYPE> system) {
        return this.tClass.isAssignableFrom(system.getClass());
    }
    
    public int getIndex() {
        return this.index;
    }
    
    public void validateRegistry(@Nonnull final ComponentRegistry<ECS_TYPE> registry) {
        if (!this.registry.equals(registry)) {
            throw new IllegalArgumentException("SystemType is for a different registry! " + String.valueOf(this));
        }
    }
    
    public void validate() {
        if (this.invalidated) {
            throw new IllegalStateException("SystemType is invalid!");
        }
    }
    
    protected void invalidate() {
        this.invalidated = true;
    }
    
    protected boolean isValid() {
        return !this.invalidated;
    }
    
    @Override
    public int compareTo(@Nonnull final SystemType<ECS_TYPE, ?> o) {
        return Integer.compare(this.index, o.getIndex());
    }
    
    @Override
    public boolean equals(@Nullable final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || this.getClass() != o.getClass()) {
            return false;
        }
        final SystemType<?, ?> that = (SystemType<?, ?>)o;
        return this.index == that.index && this.registry.equals(that.registry);
    }
    
    @Override
    public int hashCode() {
        int result = this.registry.hashCode();
        result = 31 * result + this.index;
        return result;
    }
    
    @Nonnull
    @Override
    public String toString() {
        return "SystemType{registry=" + String.valueOf(this.registry.getClass()) + "@" + this.registry.hashCode() + ", typeClass=" + String.valueOf(this.tClass) + ", index=" + this.index;
    }
    
    static {
        EMPTY_ARRAY = new SystemType[0];
    }
}
