package io.realm;


import android.util.JsonReader;
import android.util.JsonToken;
import com.mgdiez.data.bean.vo.tweet.hashtag.HashtagVo;
import io.realm.RealmFieldType;
import io.realm.exceptions.RealmMigrationNeededException;
import io.realm.internal.ColumnInfo;
import io.realm.internal.ImplicitTransaction;
import io.realm.internal.LinkView;
import io.realm.internal.RealmObjectProxy;
import io.realm.internal.Table;
import io.realm.internal.TableOrView;
import io.realm.internal.android.JsonUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class HashtagVoRealmProxy extends HashtagVo
    implements RealmObjectProxy {

    static final class HashtagVoColumnInfo extends ColumnInfo {

        public final long nTweetsIndex;
        public final long nameIndex;
        public final long queryNameIndex;

        HashtagVoColumnInfo(String path, Table table) {
            final Map<String, Long> indicesMap = new HashMap<String, Long>(3);
            this.nTweetsIndex = getValidColumnIndex(path, table, "HashtagVo", "nTweets");
            indicesMap.put("nTweets", this.nTweetsIndex);

            this.nameIndex = getValidColumnIndex(path, table, "HashtagVo", "name");
            indicesMap.put("name", this.nameIndex);

            this.queryNameIndex = getValidColumnIndex(path, table, "HashtagVo", "queryName");
            indicesMap.put("queryName", this.queryNameIndex);

            setIndicesMap(indicesMap);
        }
    }

    private final HashtagVoColumnInfo columnInfo;
    private static final List<String> FIELD_NAMES;
    static {
        List<String> fieldNames = new ArrayList<String>();
        fieldNames.add("nTweets");
        fieldNames.add("name");
        fieldNames.add("queryName");
        FIELD_NAMES = Collections.unmodifiableList(fieldNames);
    }

    HashtagVoRealmProxy(ColumnInfo columnInfo) {
        this.columnInfo = (HashtagVoColumnInfo) columnInfo;
    }

    @Override
    @SuppressWarnings("cast")
    public Integer getnTweets() {
        realm.checkIfValid();
        if (row.isNull(columnInfo.nTweetsIndex)) {
            return null;
        }
        return (int) row.getLong(columnInfo.nTweetsIndex);
    }

    @Override
    public void setnTweets(Integer value) {
        realm.checkIfValid();
        if (value == null) {
            row.setNull(columnInfo.nTweetsIndex);
            return;
        }
        row.setLong(columnInfo.nTweetsIndex, value);
    }

    @Override
    @SuppressWarnings("cast")
    public String getName() {
        realm.checkIfValid();
        return (java.lang.String) row.getString(columnInfo.nameIndex);
    }

    @Override
    public void setName(String value) {
        realm.checkIfValid();
        if (value == null) {
            throw new IllegalArgumentException("Trying to set non-nullable field name to null.");
        }
        row.setString(columnInfo.nameIndex, value);
    }

    @Override
    @SuppressWarnings("cast")
    public String getQueryName() {
        realm.checkIfValid();
        return (java.lang.String) row.getString(columnInfo.queryNameIndex);
    }

    @Override
    public void setQueryName(String value) {
        realm.checkIfValid();
        if (value == null) {
            row.setNull(columnInfo.queryNameIndex);
            return;
        }
        row.setString(columnInfo.queryNameIndex, value);
    }

    public static Table initTable(ImplicitTransaction transaction) {
        if (!transaction.hasTable("class_HashtagVo")) {
            Table table = transaction.getTable("class_HashtagVo");
            table.addColumn(RealmFieldType.INTEGER, "nTweets", Table.NULLABLE);
            table.addColumn(RealmFieldType.STRING, "name", Table.NOT_NULLABLE);
            table.addColumn(RealmFieldType.STRING, "queryName", Table.NULLABLE);
            table.addSearchIndex(table.getColumnIndex("name"));
            table.setPrimaryKey("name");
            return table;
        }
        return transaction.getTable("class_HashtagVo");
    }

    public static HashtagVoColumnInfo validateTable(ImplicitTransaction transaction) {
        if (transaction.hasTable("class_HashtagVo")) {
            Table table = transaction.getTable("class_HashtagVo");
            if (table.getColumnCount() != 3) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Field count does not match - expected 3 but was " + table.getColumnCount());
            }
            Map<String, RealmFieldType> columnTypes = new HashMap<String, RealmFieldType>();
            for (long i = 0; i < 3; i++) {
                columnTypes.put(table.getColumnName(i), table.getColumnType(i));
            }

            final HashtagVoColumnInfo columnInfo = new HashtagVoColumnInfo(transaction.getPath(), table);

            if (!columnTypes.containsKey("nTweets")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Missing field 'nTweets' in existing Realm file. Either remove field or migrate using io.realm.internal.Table.addColumn().");
            }
            if (columnTypes.get("nTweets") != RealmFieldType.INTEGER) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Invalid type 'Integer' for field 'nTweets' in existing Realm file.");
            }
            if (!table.isColumnNullable(columnInfo.nTweetsIndex)) {
                throw new RealmMigrationNeededException(transaction.getPath(),"Field 'nTweets' does not support null values in the existing Realm file. Either set @Required, use the primitive type for field 'nTweets' or migrate using io.realm.internal.Table.convertColumnToNullable().");
            }
            if (!columnTypes.containsKey("name")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Missing field 'name' in existing Realm file. Either remove field or migrate using io.realm.internal.Table.addColumn().");
            }
            if (columnTypes.get("name") != RealmFieldType.STRING) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Invalid type 'String' for field 'name' in existing Realm file.");
            }
            if (table.isColumnNullable(columnInfo.nameIndex)) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Field 'name' does support null values in the existing Realm file. Remove @Required or @PrimaryKey from field 'name' or migrate using io.realm.internal.Table.convertColumnToNotNullable().");
            }
            if (table.getPrimaryKey() != table.getColumnIndex("name")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Primary key not defined for field 'name' in existing Realm file. Add @PrimaryKey.");
            }
            if (!table.hasSearchIndex(table.getColumnIndex("name"))) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Index not defined for field 'name' in existing Realm file. Either set @Index or migrate using io.realm.internal.Table.removeSearchIndex().");
            }
            if (!columnTypes.containsKey("queryName")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Missing field 'queryName' in existing Realm file. Either remove field or migrate using io.realm.internal.Table.addColumn().");
            }
            if (columnTypes.get("queryName") != RealmFieldType.STRING) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Invalid type 'String' for field 'queryName' in existing Realm file.");
            }
            if (!table.isColumnNullable(columnInfo.queryNameIndex)) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Field 'queryName' is required. Either set @Required to field 'queryName' or migrate using io.realm.internal.Table.convertColumnToNullable().");
            }
            return columnInfo;
        } else {
            throw new RealmMigrationNeededException(transaction.getPath(), "The HashtagVo class is missing from the schema for this Realm.");
        }
    }

    public static String getTableName() {
        return "class_HashtagVo";
    }

    public static List<String> getFieldNames() {
        return FIELD_NAMES;
    }

    @SuppressWarnings("cast")
    public static HashtagVo createOrUpdateUsingJsonObject(Realm realm, JSONObject json, boolean update)
        throws JSONException {
        HashtagVo obj = null;
        if (update) {
            Table table = realm.getTable(HashtagVo.class);
            long pkColumnIndex = table.getPrimaryKey();
            if (!json.isNull("name")) {
                long rowIndex = table.findFirstString(pkColumnIndex, json.getString("name"));
                if (rowIndex != TableOrView.NO_MATCH) {
                    obj = new HashtagVoRealmProxy(realm.schema.getColumnInfo(HashtagVo.class));
                    obj.realm = realm;
                    obj.row = table.getUncheckedRow(rowIndex);
                }
            }
        }
        if (obj == null) {
            if (json.has("name")) {
                if (json.isNull("name")) {
                    obj = realm.createObject(HashtagVo.class, null);
                } else {
                    obj = realm.createObject(HashtagVo.class, json.getString("name"));
                }
            } else {
                obj = realm.createObject(HashtagVo.class);
            }
        }
        if (json.has("nTweets")) {
            if (json.isNull("nTweets")) {
                obj.setnTweets(null);
            } else {
                obj.setnTweets((int) json.getInt("nTweets"));
            }
        }
        if (json.has("name")) {
            if (json.isNull("name")) {
                obj.setName(null);
            } else {
                obj.setName((String) json.getString("name"));
            }
        }
        if (json.has("queryName")) {
            if (json.isNull("queryName")) {
                obj.setQueryName(null);
            } else {
                obj.setQueryName((String) json.getString("queryName"));
            }
        }
        return obj;
    }

    @SuppressWarnings("cast")
    public static HashtagVo createUsingJsonStream(Realm realm, JsonReader reader)
        throws IOException {
        HashtagVo obj = realm.createObject(HashtagVo.class);
        reader.beginObject();
        while (reader.hasNext()) {
            String name = reader.nextName();
            if (name.equals("nTweets")) {
                if (reader.peek() == JsonToken.NULL) {
                    reader.skipValue();
                    obj.setnTweets(null);
                } else {
                    obj.setnTweets((int) reader.nextInt());
                }
            } else if (name.equals("name")) {
                if (reader.peek() == JsonToken.NULL) {
                    reader.skipValue();
                    obj.setName(null);
                } else {
                    obj.setName((String) reader.nextString());
                }
            } else if (name.equals("queryName")) {
                if (reader.peek() == JsonToken.NULL) {
                    reader.skipValue();
                    obj.setQueryName(null);
                } else {
                    obj.setQueryName((String) reader.nextString());
                }
            } else {
                reader.skipValue();
            }
        }
        reader.endObject();
        return obj;
    }

    public static HashtagVo copyOrUpdate(Realm realm, HashtagVo object, boolean update, Map<RealmObject,RealmObjectProxy> cache) {
        if (object.realm != null && object.realm.getPath().equals(realm.getPath())) {
            return object;
        }
        HashtagVo realmObject = null;
        boolean canUpdate = update;
        if (canUpdate) {
            Table table = realm.getTable(HashtagVo.class);
            long pkColumnIndex = table.getPrimaryKey();
            if (object.getName() == null) {
                throw new IllegalArgumentException("Primary key value must not be null.");
            }
            long rowIndex = table.findFirstString(pkColumnIndex, object.getName());
            if (rowIndex != TableOrView.NO_MATCH) {
                realmObject = new HashtagVoRealmProxy(realm.schema.getColumnInfo(HashtagVo.class));
                realmObject.realm = realm;
                realmObject.row = table.getUncheckedRow(rowIndex);
                cache.put(object, (RealmObjectProxy) realmObject);
            } else {
                canUpdate = false;
            }
        }

        if (canUpdate) {
            return update(realm, realmObject, object, cache);
        } else {
            return copy(realm, object, update, cache);
        }
    }

    public static HashtagVo copy(Realm realm, HashtagVo newObject, boolean update, Map<RealmObject,RealmObjectProxy> cache) {
        HashtagVo realmObject = realm.createObject(HashtagVo.class, newObject.getName());
        cache.put(newObject, (RealmObjectProxy) realmObject);
        realmObject.setnTweets(newObject.getnTweets());
        realmObject.setName(newObject.getName());
        realmObject.setQueryName(newObject.getQueryName());
        return realmObject;
    }

    public static HashtagVo createDetachedCopy(HashtagVo realmObject, int currentDepth, int maxDepth, Map<RealmObject, CacheData<RealmObject>> cache) {
        if (currentDepth > maxDepth || realmObject == null) {
            return null;
        }
        CacheData<HashtagVo> cachedObject = (CacheData) cache.get(realmObject);
        HashtagVo standaloneObject;
        if (cachedObject != null) {
            // Reuse cached object or recreate it because it was encountered at a lower depth.
            if (currentDepth >= cachedObject.minDepth) {
                return cachedObject.object;
            } else {
                standaloneObject = cachedObject.object;
                cachedObject.minDepth = currentDepth;
            }
        } else {
            standaloneObject = new HashtagVo();
            cache.put(realmObject, new RealmObjectProxy.CacheData<RealmObject>(currentDepth, standaloneObject));
        }
        standaloneObject.setnTweets(realmObject.getnTweets());
        standaloneObject.setName(realmObject.getName());
        standaloneObject.setQueryName(realmObject.getQueryName());
        return standaloneObject;
    }

    static HashtagVo update(Realm realm, HashtagVo realmObject, HashtagVo newObject, Map<RealmObject, RealmObjectProxy> cache) {
        realmObject.setnTweets(newObject.getnTweets());
        realmObject.setQueryName(newObject.getQueryName());
        return realmObject;
    }

    @Override
    public String toString() {
        if (!isValid()) {
            return "Invalid object";
        }
        StringBuilder stringBuilder = new StringBuilder("HashtagVo = [");
        stringBuilder.append("{nTweets:");
        stringBuilder.append(getnTweets() != null ? getnTweets() : "null");
        stringBuilder.append("}");
        stringBuilder.append(",");
        stringBuilder.append("{name:");
        stringBuilder.append(getName());
        stringBuilder.append("}");
        stringBuilder.append(",");
        stringBuilder.append("{queryName:");
        stringBuilder.append(getQueryName() != null ? getQueryName() : "null");
        stringBuilder.append("}");
        stringBuilder.append("]");
        return stringBuilder.toString();
    }

    @Override
    public int hashCode() {
        String realmName = realm.getPath();
        String tableName = row.getTable().getName();
        long rowIndex = row.getIndex();

        int result = 17;
        result = 31 * result + ((realmName != null) ? realmName.hashCode() : 0);
        result = 31 * result + ((tableName != null) ? tableName.hashCode() : 0);
        result = 31 * result + (int) (rowIndex ^ (rowIndex >>> 32));
        return result;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        HashtagVoRealmProxy aHashtagVo = (HashtagVoRealmProxy)o;

        String path = realm.getPath();
        String otherPath = aHashtagVo.realm.getPath();
        if (path != null ? !path.equals(otherPath) : otherPath != null) return false;;

        String tableName = row.getTable().getName();
        String otherTableName = aHashtagVo.row.getTable().getName();
        if (tableName != null ? !tableName.equals(otherTableName) : otherTableName != null) return false;

        if (row.getIndex() != aHashtagVo.row.getIndex()) return false;

        return true;
    }

}
