package io.realm;


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

    static final class StringVoColumnInfo extends ColumnInfo {

        public final long stringValueIndex;

        StringVoColumnInfo(String path, Table table) {
            final Map<String, Long> indicesMap = new HashMap<String, Long>(1);
            this.stringValueIndex = getValidColumnIndex(path, table, "StringVo", "stringValue");
            indicesMap.put("stringValue", this.stringValueIndex);

            setIndicesMap(indicesMap);
        }
    }

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

    StringVoRealmProxy(ColumnInfo columnInfo) {
        this.columnInfo = (StringVoColumnInfo) columnInfo;
    }

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

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

    public static Table initTable(ImplicitTransaction transaction) {
        if (!transaction.hasTable("class_StringVo")) {
            Table table = transaction.getTable("class_StringVo");
            table.addColumn(RealmFieldType.STRING, "stringValue", Table.NULLABLE);
            table.setPrimaryKey("");
            return table;
        }
        return transaction.getTable("class_StringVo");
    }

    public static StringVoColumnInfo validateTable(ImplicitTransaction transaction) {
        if (transaction.hasTable("class_StringVo")) {
            Table table = transaction.getTable("class_StringVo");
            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 StringVoColumnInfo columnInfo = new StringVoColumnInfo(transaction.getPath(), table);

            if (!columnTypes.containsKey("stringValue")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Missing field 'stringValue' in existing Realm file. Either remove field or migrate using io.realm.internal.Table.addColumn().");
            }
            if (columnTypes.get("stringValue") != RealmFieldType.STRING) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Invalid type 'String' for field 'stringValue' in existing Realm file.");
            }
            if (!table.isColumnNullable(columnInfo.stringValueIndex)) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Field 'stringValue' is required. Either set @Required to field 'stringValue' or migrate using io.realm.internal.Table.convertColumnToNullable().");
            }
            return columnInfo;
        } else {
            throw new RealmMigrationNeededException(transaction.getPath(), "The StringVo class is missing from the schema for this Realm.");
        }
    }

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

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

    @SuppressWarnings("cast")
    public static StringVo createOrUpdateUsingJsonObject(Realm realm, JSONObject json, boolean update)
        throws JSONException {
        StringVo obj = realm.createObject(StringVo.class);
        if (json.has("stringValue")) {
            if (json.isNull("stringValue")) {
                obj.setStringValue(null);
            } else {
                obj.setStringValue((String) json.getString("stringValue"));
            }
        }
        return obj;
    }

    @SuppressWarnings("cast")
    public static StringVo createUsingJsonStream(Realm realm, JsonReader reader)
        throws IOException {
        StringVo obj = realm.createObject(StringVo.class);
        reader.beginObject();
        while (reader.hasNext()) {
            String name = reader.nextName();
            if (name.equals("stringValue")) {
                if (reader.peek() == JsonToken.NULL) {
                    reader.skipValue();
                    obj.setStringValue(null);
                } else {
                    obj.setStringValue((String) reader.nextString());
                }
            } else {
                reader.skipValue();
            }
        }
        reader.endObject();
        return obj;
    }

    public static StringVo copyOrUpdate(Realm realm, StringVo 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 StringVo copy(Realm realm, StringVo newObject, boolean update, Map<RealmObject,RealmObjectProxy> cache) {
        StringVo realmObject = realm.createObject(StringVo.class);
        cache.put(newObject, (RealmObjectProxy) realmObject);
        realmObject.setStringValue(newObject.getStringValue());
        return realmObject;
    }

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

    @Override
    public String toString() {
        if (!isValid()) {
            return "Invalid object";
        }
        StringBuilder stringBuilder = new StringBuilder("StringVo = [");
        stringBuilder.append("{stringValue:");
        stringBuilder.append(getStringValue() != null ? getStringValue() : "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;
        StringVoRealmProxy aStringVo = (StringVoRealmProxy)o;

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

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

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

        return true;
    }

}
