package com.turlir.abakgists.model;


import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.google.gson.annotations.SerializedName;
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn;
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType;

@StorIOSQLiteType(table = "gists")
public class Gist implements Parcelable {

    @SerializedName("url")
    @StorIOSQLiteColumn(name = "url")
    @NonNull
    public String url;

    @SerializedName("id")
    @StorIOSQLiteColumn(name = "id", key = true)
    @NonNull
    public String id;

    @SerializedName("description")
    @StorIOSQLiteColumn(name = "desc")
    @Nullable
    public String description;

    @SerializedName("created_at")
    @StorIOSQLiteColumn(name = "created")
    @NonNull
    public String created;

    ////////

    @SerializedName("owner")
    @Nullable
    public GistOwner owner;

    @StorIOSQLiteColumn(name = "ownerLogin")
    @Nullable
    public String ownerLogin;

    @StorIOSQLiteColumn(name = "ownerAvatarUrl")
    @Nullable
    public String ownerAvatarUrl;

    ////////

    @StorIOSQLiteColumn(name = "note")
    @Nullable
    public String note;

    public static final Creator<Gist> CREATOR = new Creator<Gist>() {
        @Override
        public Gist createFromParcel(Parcel in) {
            return new Gist(in);
        }

        @Override
        public Gist[] newArray(int size) {
            return new Gist[size];
        }
    };

    public Gist() {

    }

    protected Gist(Parcel in) {
        url = in.readString();
        id = in.readString();
        description = in.readString();
        created = in.readString();
        ownerLogin = in.readString();
        ownerAvatarUrl = in.readString();
        note = in.readString();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(url);
        dest.writeString(id);
        dest.writeString(description);
        dest.writeString(created);
        dest.writeString(ownerLogin);
        dest.writeString(ownerAvatarUrl);
        dest.writeString(note);
    }

    @Override
    public int describeContents() {
        return 0;
    }

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

        Gist gist = (Gist) o;

        if (!url.equals(gist.url)) return false;
        if (!id.equals(gist.id)) return false;
        if (!created.equals(gist.created)) return false;

        if (description != null ? !description.equals(gist.description) : gist.description != null) return false;
        if (ownerLogin != null ? !ownerLogin.equals(gist.ownerLogin) : gist.ownerLogin != null) return false;
        if (ownerAvatarUrl != null ? !ownerAvatarUrl.equals(gist.ownerAvatarUrl) : gist.ownerAvatarUrl != null) return false;

        return note != null ? note.equals(gist.note) : gist.note == null;
    }

    @Override
    public int hashCode() {
        int result = url.hashCode();
        result = 31 * result + id.hashCode();
        result = 31 * result + (description != null ? description.hashCode() : 0);
        result = 31 * result + created.hashCode();
        result = 31 * result + (ownerLogin != null ? ownerLogin.hashCode() : 0);
        result = 31 * result + (ownerAvatarUrl != null ? ownerAvatarUrl.hashCode() : 0);
        result = 31 * result + (note != null ? note.hashCode() : 0);
        return result;
    }
}

@@ -397,15 +397,24 @@
 e = 
-%22g
+G
 ists
-%22
+Table.GISTS
 )%0Apu
@@ -512,21 +512,30 @@
 (name = 
-%22url%22
+GistsTable.URL
 )%0A    @N
@@ -622,20 +622,29 @@
 (name = 
-%22id%22
+GistsTable.ID
 , key = 
@@ -755,14 +755,23 @@
 e = 
-%22desc%22
+GistsTable.DESC
 )%0A  
@@ -883,17 +883,26 @@
 e = 
-%22created%22
+GistsTable.CREATED
 )%0A  
@@ -1061,20 +1061,30 @@
 e = 
-%22ownerLogin%22
+GistsTable.OWNER_LOGIN
 )%0A  
@@ -1161,24 +1161,31 @@
 e = 
-%22ownerAvatarUrl%22
+GistsTable.OWNER_AVATAR
 )%0A  
@@ -1280,14 +1280,23 @@
 e = 
-%22note%22
+GistsTable.NOTE
 )%0A  

use GistsTable constants everywhere