package io.realm;


import android.util.JsonReader;
import android.util.JsonToken;
import com.mgdiez.data.bean.vo.tweet.IntegerVo;
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 IntegerVoRealmProxy extends IntegerVo
    implements RealmObjectProxy {

    static final class IntegerVoColumnInfo extends ColumnInfo {

        public final long integerIndex;

        IntegerVoColumnInfo(String path, Table table) {
            final Map<String, Long> indicesMap = new HashMap<String, Long>(1);
            this.integerIndex = getValidColumnIndex(path, table, "IntegerVo", "integer");
            indicesMap.put("integer", this.integerIndex);

            setIndicesMap(indicesMap);
        }
    }

    private final IntegerVoColumnInfo columnInfo;
    private static final List<String> FIELD_NAMES;
    static {
        List<String> fieldNames = new ArrayList<String>();
        fieldNames.add("integer");
        FIELD_NAMES = Collections.unmodifiableList(fieldNames);
    }

    IntegerVoRealmProxy(ColumnInfo columnInfo) {
        this.columnInfo = (IntegerVoColumnInfo) columnInfo;
    }

    @Override
    @SuppressWarnings("cast")
    public int getInteger() {
        realm.checkIfValid();
        return (int) row.getLong(columnInfo.integerIndex);
    }

    @Override
    public void setInteger(int value) {
        realm.checkIfValid();
        row.setLong(columnInfo.integerIndex, value);
    }

    public static Table initTable(ImplicitTransaction transaction) {
        if (!transaction.hasTable("class_IntegerVo")) {
            Table table = transaction.getTable("class_IntegerVo");
            table.addColumn(RealmFieldType.INTEGER, "integer", Table.NOT_NULLABLE);
            table.setPrimaryKey("");
            return table;
        }
        return transaction.getTable("class_IntegerVo");
    }

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

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

            if (!columnTypes.containsKey("integer")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Missing field 'integer' in existing Realm file. Either remove field or migrate using io.realm.internal.Table.addColumn().");
            }
            if (columnTypes.get("integer") != RealmFieldType.INTEGER) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Invalid type 'int' for field 'integer' in existing Realm file.");
            }
            if (table.isColumnNullable(columnInfo.integerIndex)) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Field 'integer' does support null values in the existing Realm file. Use corresponding boxed type for field 'integer' or migrate using io.realm.internal.Table.convertColumnToNotNullable().");
            }
            return columnInfo;
        } else {
            throw new RealmMigrationNeededException(transaction.getPath(), "The IntegerVo class is missing from the schema for this Realm.");
        }
    }

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

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

    @SuppressWarnings("cast")
    public static IntegerVo createOrUpdateUsingJsonObject(Realm realm, JSONObject json, boolean update)
        throws JSONException {
        IntegerVo obj = realm.createObject(IntegerVo.class);
        if (json.has("integer")) {
            if (json.isNull("integer")) {
                throw new IllegalArgumentException("Trying to set non-nullable field integer to null.");
            } else {
                obj.setInteger((int) json.getInt("integer"));
            }
        }
        return obj;
    }

    @SuppressWarnings("cast")
    public static IntegerVo createUsingJsonStream(Realm realm, JsonReader reader)
        throws IOException {
        IntegerVo obj = realm.createObject(IntegerVo.class);
        reader.beginObject();
        while (reader.hasNext()) {
            String name = reader.nextName();
            if (name.equals("integer")) {
                if (reader.peek() == JsonToken.NULL) {
                    reader.skipValue();
                    throw new IllegalArgumentException("Trying to set non-nullable field integer to null.");
                } else {
                    obj.setInteger((int) reader.nextInt());
                }
            } else {
                reader.skipValue();
            }
        }
        reader.endObject();
        return obj;
    }

    public static IntegerVo copyOrUpdate(Realm realm, IntegerVo object, boolean update, Map<RealmObject,RealmObjectProxy> cache) {
        if (object.realm != null && object.realm.getPath().equals(realm.getPath())) {
            return object;
        }
        return copy(realm, object, update, cache);
    }

    public static IntegerVo copy(Realm realm, IntegerVo newObject, boolean update, Map<RealmObject,RealmObjectProxy> cache) {
        IntegerVo realmObject = realm.createObject(IntegerVo.class);
        cache.put(newObject, (RealmObjectProxy) realmObject);
        realmObject.setInteger(newObject.getInteger());
        return realmObject;
    }

    public static IntegerVo createDetachedCopy(IntegerVo realmObject, int currentDepth, int maxDepth, Map<RealmObject, CacheData<RealmObject>> cache) {
        if (currentDepth > maxDepth || realmObject == null) {
            return null;
        }
        CacheData<IntegerVo> cachedObject = (CacheData) cache.get(realmObject);
        IntegerVo 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 IntegerVo();
            cache.put(realmObject, new RealmObjectProxy.CacheData<RealmObject>(currentDepth, standaloneObject));
        }
        standaloneObject.setInteger(realmObject.getInteger());
        return standaloneObject;
    }

    @Override
    public String toString() {
        if (!isValid()) {
            return "Invalid object";
        }
        StringBuilder stringBuilder = new StringBuilder("IntegerVo = [");
        stringBuilder.append("{integer:");
        stringBuilder.append(getInteger());
        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;
        IntegerVoRealmProxy aIntegerVo = (IntegerVoRealmProxy)o;

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

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

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

        return true;
    }

}
