package io.realm;


import android.util.JsonReader;
import io.realm.internal.ColumnInfo;
import io.realm.internal.ImplicitTransaction;
import io.realm.internal.RealmObjectProxy;
import io.realm.internal.RealmProxyMediator;
import io.realm.internal.Table;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.json.JSONException;
import org.json.JSONObject;
import com.mgdiez.data.bean.vo.tweet.IntegerVo;
import com.mgdiez.data.bean.vo.tweet.StatisticVo;
import com.mgdiez.data.bean.vo.tweet.StringVo;
import com.mgdiez.data.bean.vo.tweet.TweetVo;
import com.mgdiez.data.bean.vo.tweet.UserVo;
import com.mgdiez.data.bean.vo.tweet.hashtag.HashtagVo;

@io.realm.annotations.RealmModule
class DefaultRealmModuleMediator extends RealmProxyMediator {

    private static final Set<Class<? extends RealmObject>> MODEL_CLASSES;
    static {
        Set<Class<? extends RealmObject>> modelClasses = new HashSet<Class<? extends RealmObject>>();
        modelClasses.add(TweetVo.class);
        modelClasses.add(HashtagVo.class);
        modelClasses.add(IntegerVo.class);
        modelClasses.add(StringVo.class);
        modelClasses.add(UserVo.class);
        modelClasses.add(StatisticVo.class);
        MODEL_CLASSES = Collections.unmodifiableSet(modelClasses);
    }

    @Override
    public Table createTable(Class<? extends RealmObject> clazz, ImplicitTransaction transaction) {
        checkClass(clazz);

        if (clazz.equals(TweetVo.class)) {
            return TweetVoRealmProxy.initTable(transaction);
        } else if (clazz.equals(HashtagVo.class)) {
            return HashtagVoRealmProxy.initTable(transaction);
        } else if (clazz.equals(IntegerVo.class)) {
            return IntegerVoRealmProxy.initTable(transaction);
        } else if (clazz.equals(StringVo.class)) {
            return StringVoRealmProxy.initTable(transaction);
        } else if (clazz.equals(UserVo.class)) {
            return UserVoRealmProxy.initTable(transaction);
        } else if (clazz.equals(StatisticVo.class)) {
            return StatisticVoRealmProxy.initTable(transaction);
        } else {
            throw getMissingProxyClassException(clazz);
        }
    }

    @Override
    public ColumnInfo validateTable(Class<? extends RealmObject> clazz, ImplicitTransaction transaction) {
        checkClass(clazz);

        if (clazz.equals(TweetVo.class)) {
            return TweetVoRealmProxy.validateTable(transaction);
        } else if (clazz.equals(HashtagVo.class)) {
            return HashtagVoRealmProxy.validateTable(transaction);
        } else if (clazz.equals(IntegerVo.class)) {
            return IntegerVoRealmProxy.validateTable(transaction);
        } else if (clazz.equals(StringVo.class)) {
            return StringVoRealmProxy.validateTable(transaction);
        } else if (clazz.equals(UserVo.class)) {
            return UserVoRealmProxy.validateTable(transaction);
        } else if (clazz.equals(StatisticVo.class)) {
            return StatisticVoRealmProxy.validateTable(transaction);
        } else {
            throw getMissingProxyClassException(clazz);
        }
    }

    @Override
    public List<String> getFieldNames(Class<? extends RealmObject> clazz) {
        checkClass(clazz);

        if (clazz.equals(TweetVo.class)) {
            return TweetVoRealmProxy.getFieldNames();
        } else if (clazz.equals(HashtagVo.class)) {
            return HashtagVoRealmProxy.getFieldNames();
        } else if (clazz.equals(IntegerVo.class)) {
            return IntegerVoRealmProxy.getFieldNames();
        } else if (clazz.equals(StringVo.class)) {
            return StringVoRealmProxy.getFieldNames();
        } else if (clazz.equals(UserVo.class)) {
            return UserVoRealmProxy.getFieldNames();
        } else if (clazz.equals(StatisticVo.class)) {
            return StatisticVoRealmProxy.getFieldNames();
        } else {
            throw getMissingProxyClassException(clazz);
        }
    }

    @Override
    public String getTableName(Class<? extends RealmObject> clazz) {
        checkClass(clazz);

        if (clazz.equals(TweetVo.class)) {
            return TweetVoRealmProxy.getTableName();
        } else if (clazz.equals(HashtagVo.class)) {
            return HashtagVoRealmProxy.getTableName();
        } else if (clazz.equals(IntegerVo.class)) {
            return IntegerVoRealmProxy.getTableName();
        } else if (clazz.equals(StringVo.class)) {
            return StringVoRealmProxy.getTableName();
        } else if (clazz.equals(UserVo.class)) {
            return UserVoRealmProxy.getTableName();
        } else if (clazz.equals(StatisticVo.class)) {
            return StatisticVoRealmProxy.getTableName();
        } else {
            throw getMissingProxyClassException(clazz);
        }
    }

    @Override
    public <E extends RealmObject> E newInstance(Class<E> clazz, ColumnInfo columnInfo) {
        checkClass(clazz);

        if (clazz.equals(TweetVo.class)) {
            return clazz.cast(new TweetVoRealmProxy(columnInfo));
        } else if (clazz.equals(HashtagVo.class)) {
            return clazz.cast(new HashtagVoRealmProxy(columnInfo));
        } else if (clazz.equals(IntegerVo.class)) {
            return clazz.cast(new IntegerVoRealmProxy(columnInfo));
        } else if (clazz.equals(StringVo.class)) {
            return clazz.cast(new StringVoRealmProxy(columnInfo));
        } else if (clazz.equals(UserVo.class)) {
            return clazz.cast(new UserVoRealmProxy(columnInfo));
        } else if (clazz.equals(StatisticVo.class)) {
            return clazz.cast(new StatisticVoRealmProxy(columnInfo));
        } else {
            throw getMissingProxyClassException(clazz);
        }
    }

    @Override
    public Set<Class<? extends RealmObject>> getModelClasses() {
        return MODEL_CLASSES;
    }

    @Override
    public <E extends RealmObject> E copyOrUpdate(Realm realm, E obj, boolean update, Map<RealmObject, RealmObjectProxy> cache) {
        // This cast is correct because obj is either
        // generated by RealmProxy or the original type extending directly from RealmObject
        @SuppressWarnings("unchecked") Class<E> clazz = (Class<E>) ((obj instanceof RealmObjectProxy) ? obj.getClass().getSuperclass() : obj.getClass());

        if (clazz.equals(TweetVo.class)) {
            return clazz.cast(TweetVoRealmProxy.copyOrUpdate(realm, (TweetVo) obj, update, cache));
        } else if (clazz.equals(HashtagVo.class)) {
            return clazz.cast(HashtagVoRealmProxy.copyOrUpdate(realm, (HashtagVo) obj, update, cache));
        } else if (clazz.equals(IntegerVo.class)) {
            return clazz.cast(IntegerVoRealmProxy.copyOrUpdate(realm, (IntegerVo) obj, update, cache));
        } else if (clazz.equals(StringVo.class)) {
            return clazz.cast(StringVoRealmProxy.copyOrUpdate(realm, (StringVo) obj, update, cache));
        } else if (clazz.equals(UserVo.class)) {
            return clazz.cast(UserVoRealmProxy.copyOrUpdate(realm, (UserVo) obj, update, cache));
        } else if (clazz.equals(StatisticVo.class)) {
            return clazz.cast(StatisticVoRealmProxy.copyOrUpdate(realm, (StatisticVo) obj, update, cache));
        } else {
            throw getMissingProxyClassException(clazz);
        }
    }

    @Override
    public <E extends RealmObject> E createOrUpdateUsingJsonObject(Class<E> clazz, Realm realm, JSONObject json, boolean update)
        throws JSONException {
        checkClass(clazz);

        if (clazz.equals(TweetVo.class)) {
            return clazz.cast(TweetVoRealmProxy.createOrUpdateUsingJsonObject(realm, json, update));
        } else if (clazz.equals(HashtagVo.class)) {
            return clazz.cast(HashtagVoRealmProxy.createOrUpdateUsingJsonObject(realm, json, update));
        } else if (clazz.equals(IntegerVo.class)) {
            return clazz.cast(IntegerVoRealmProxy.createOrUpdateUsingJsonObject(realm, json, update));
        } else if (clazz.equals(StringVo.class)) {
            return clazz.cast(StringVoRealmProxy.createOrUpdateUsingJsonObject(realm, json, update));
        } else if (clazz.equals(UserVo.class)) {
            return clazz.cast(UserVoRealmProxy.createOrUpdateUsingJsonObject(realm, json, update));
        } else if (clazz.equals(StatisticVo.class)) {
            return clazz.cast(StatisticVoRealmProxy.createOrUpdateUsingJsonObject(realm, json, update));
        } else {
            throw getMissingProxyClassException(clazz);
        }
    }

    @Override
    public <E extends RealmObject> E createUsingJsonStream(Class<E> clazz, Realm realm, JsonReader reader)
        throws IOException {
        checkClass(clazz);

        if (clazz.equals(TweetVo.class)) {
            return clazz.cast(TweetVoRealmProxy.createUsingJsonStream(realm, reader));
        } else if (clazz.equals(HashtagVo.class)) {
            return clazz.cast(HashtagVoRealmProxy.createUsingJsonStream(realm, reader));
        } else if (clazz.equals(IntegerVo.class)) {
            return clazz.cast(IntegerVoRealmProxy.createUsingJsonStream(realm, reader));
        } else if (clazz.equals(StringVo.class)) {
            return clazz.cast(StringVoRealmProxy.createUsingJsonStream(realm, reader));
        } else if (clazz.equals(UserVo.class)) {
            return clazz.cast(UserVoRealmProxy.createUsingJsonStream(realm, reader));
        } else if (clazz.equals(StatisticVo.class)) {
            return clazz.cast(StatisticVoRealmProxy.createUsingJsonStream(realm, reader));
        } else {
            throw getMissingProxyClassException(clazz);
        }
    }

    @Override
    public <E extends RealmObject> E createDetachedCopy(E realmObject, int maxDepth, Map<RealmObject, RealmObjectProxy.CacheData<RealmObject>> cache) {
        // This cast is correct because obj is either
        // generated by RealmProxy or the original type extending directly from RealmObject
        @SuppressWarnings("unchecked") Class<E> clazz = (Class<E>) realmObject.getClass().getSuperclass();

        if (clazz.equals(TweetVo.class)) {
            return clazz.cast(TweetVoRealmProxy.createDetachedCopy((TweetVo) realmObject, 0, maxDepth, cache));
        } else if (clazz.equals(HashtagVo.class)) {
            return clazz.cast(HashtagVoRealmProxy.createDetachedCopy((HashtagVo) realmObject, 0, maxDepth, cache));
        } else if (clazz.equals(IntegerVo.class)) {
            return clazz.cast(IntegerVoRealmProxy.createDetachedCopy((IntegerVo) realmObject, 0, maxDepth, cache));
        } else if (clazz.equals(StringVo.class)) {
            return clazz.cast(StringVoRealmProxy.createDetachedCopy((StringVo) realmObject, 0, maxDepth, cache));
        } else if (clazz.equals(UserVo.class)) {
            return clazz.cast(UserVoRealmProxy.createDetachedCopy((UserVo) realmObject, 0, maxDepth, cache));
        } else if (clazz.equals(StatisticVo.class)) {
            return clazz.cast(StatisticVoRealmProxy.createDetachedCopy((StatisticVo) realmObject, 0, maxDepth, cache));
        } else {
            throw getMissingProxyClassException(clazz);
        }
    }

}
