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

package org.bson.codecs.pojo;

import java.util.Iterator;
import java.util.Collection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.List;

public final class ClassModel<T>
{
    private final String name;
    private final Class<T> type;
    private final boolean hasTypeParameters;
    private final InstanceCreatorFactory<T> instanceCreatorFactory;
    private final boolean discriminatorEnabled;
    private final String discriminatorKey;
    private final String discriminator;
    private final IdPropertyModelHolder<?> idPropertyModelHolder;
    private final List<PropertyModel<?>> propertyModels;
    private final Map<String, TypeParameterMap> propertyNameToTypeParameterMap;
    
    ClassModel(final Class<T> clazz, final Map<String, TypeParameterMap> propertyNameToTypeParameterMap, final InstanceCreatorFactory<T> instanceCreatorFactory, final Boolean discriminatorEnabled, final String discriminatorKey, final String discriminator, final IdPropertyModelHolder<?> idPropertyModelHolder, final List<PropertyModel<?>> propertyModels) {
        this.name = clazz.getSimpleName();
        this.type = clazz;
        this.hasTypeParameters = (clazz.getTypeParameters().length > 0);
        this.propertyNameToTypeParameterMap = Collections.unmodifiableMap((Map<? extends String, ? extends TypeParameterMap>)new HashMap<String, TypeParameterMap>(propertyNameToTypeParameterMap));
        this.instanceCreatorFactory = instanceCreatorFactory;
        this.discriminatorEnabled = discriminatorEnabled;
        this.discriminatorKey = discriminatorKey;
        this.discriminator = discriminator;
        this.idPropertyModelHolder = idPropertyModelHolder;
        this.propertyModels = Collections.unmodifiableList((List<? extends PropertyModel<?>>)new ArrayList<PropertyModel<?>>(propertyModels));
    }
    
    public static <S> ClassModelBuilder<S> builder(final Class<S> type) {
        return new ClassModelBuilder<S>(type);
    }
    
    InstanceCreator<T> getInstanceCreator() {
        return this.instanceCreatorFactory.create();
    }
    
    public Class<T> getType() {
        return this.type;
    }
    
    public boolean hasTypeParameters() {
        return this.hasTypeParameters;
    }
    
    public boolean useDiscriminator() {
        return this.discriminatorEnabled;
    }
    
    public String getDiscriminatorKey() {
        return this.discriminatorKey;
    }
    
    public String getDiscriminator() {
        return this.discriminator;
    }
    
    public PropertyModel<?> getPropertyModel(final String propertyName) {
        for (final PropertyModel<?> propertyModel : this.propertyModels) {
            if (propertyModel.getName().equals(propertyName)) {
                return propertyModel;
            }
        }
        return null;
    }
    
    public List<PropertyModel<?>> getPropertyModels() {
        return this.propertyModels;
    }
    
    public PropertyModel<?> getIdPropertyModel() {
        return (this.idPropertyModelHolder != null) ? this.idPropertyModelHolder.getPropertyModel() : null;
    }
    
    IdPropertyModelHolder<?> getIdPropertyModelHolder() {
        return this.idPropertyModelHolder;
    }
    
    public String getName() {
        return this.name;
    }
    
    @Override
    public String toString() {
        return "ClassModel{type=" + this.type + "}";
    }
    
    @Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || this.getClass() != o.getClass()) {
            return false;
        }
        final ClassModel<?> that = (ClassModel<?>)o;
        if (this.discriminatorEnabled != that.discriminatorEnabled) {
            return false;
        }
        if (!this.getType().equals(that.getType())) {
            return false;
        }
        if (!this.getInstanceCreatorFactory().equals(that.getInstanceCreatorFactory())) {
            return false;
        }
        Label_0107: {
            if (this.getDiscriminatorKey() != null) {
                if (this.getDiscriminatorKey().equals(that.getDiscriminatorKey())) {
                    break Label_0107;
                }
            }
            else if (that.getDiscriminatorKey() == null) {
                break Label_0107;
            }
            return false;
        }
        Label_0140: {
            if (this.getDiscriminator() != null) {
                if (this.getDiscriminator().equals(that.getDiscriminator())) {
                    break Label_0140;
                }
            }
            else if (that.getDiscriminator() == null) {
                break Label_0140;
            }
            return false;
        }
        if (this.idPropertyModelHolder != null) {
            if (this.idPropertyModelHolder.equals(that.idPropertyModelHolder)) {
                return this.getPropertyModels().equals(that.getPropertyModels()) && this.getPropertyNameToTypeParameterMap().equals(that.getPropertyNameToTypeParameterMap());
            }
        }
        else if (that.idPropertyModelHolder == null) {
            return this.getPropertyModels().equals(that.getPropertyModels()) && this.getPropertyNameToTypeParameterMap().equals(that.getPropertyNameToTypeParameterMap());
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        int result = this.getType().hashCode();
        result = 31 * result + this.getInstanceCreatorFactory().hashCode();
        result = 31 * result + (this.discriminatorEnabled ? 1 : 0);
        result = 31 * result + ((this.getDiscriminatorKey() != null) ? this.getDiscriminatorKey().hashCode() : 0);
        result = 31 * result + ((this.getDiscriminator() != null) ? this.getDiscriminator().hashCode() : 0);
        result = 31 * result + ((this.getIdPropertyModelHolder() != null) ? this.getIdPropertyModelHolder().hashCode() : 0);
        result = 31 * result + this.getPropertyModels().hashCode();
        result = 31 * result + this.getPropertyNameToTypeParameterMap().hashCode();
        return result;
    }
    
    InstanceCreatorFactory<T> getInstanceCreatorFactory() {
        return this.instanceCreatorFactory;
    }
    
    Map<String, TypeParameterMap> getPropertyNameToTypeParameterMap() {
        return this.propertyNameToTypeParameterMap;
    }
}
