package it.near.sdk.reactions.contentplugin.model;

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

import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import it.near.sdk.morpheusnear.annotations.Relationship;
import it.near.sdk.recipes.models.ReactionBundle;

public class Content extends ReactionBundle implements Parcelable {
    @SerializedName("title")
    public String title;

    @SerializedName("content")
    public String contentString;

    @SerializedName("link")
    public HashMap<String, Object> link;

    @SerializedName("updated_at")
    public String updated_at;

    @Deprecated
    @Relationship("images")
    public List<Image> images;

    @Deprecated
    @Relationship("audio")
    public Audio audio;

    @Deprecated
    @Relationship("upload")
    public Upload upload;

    @Deprecated
    @SerializedName("video_link")
    public String video_link;

    private List<ImageSet> images_links;
    private ContentLink cta;

    public Content() {
    }

    @Deprecated
    public List<ImageSet> getImages_links() {
        return images_links;
    }

    @Nullable
    public ContentLink getCta() {
        return cta;
    }

    public void setCta(ContentLink cta) {
        this.cta = cta;
    }

    @Deprecated
    public void setImages_links(List<ImageSet> images_links) {
        this.images_links = images_links;
    }

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

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeString(title);
        dest.writeString(contentString);
        dest.writeString(video_link);
        dest.writeString(updated_at);
        dest.writeString(getId());
        dest.writeTypedList(getImages_links());
        dest.writeParcelable(cta, flags);
        dest.writeParcelable(audio, flags);
        dest.writeParcelable(upload, flags);
    }

    // Creator
    public static final Parcelable.Creator<Content> CREATOR = new Parcelable.Creator<Content>() {
        public Content createFromParcel(Parcel in) {
            return new Content(in);
        }

        public Content[] newArray(int size) {
            return new Content[size];
        }
    };

    public Content(Parcel in) {
        super(in);
        title = in.readString();
        contentString = in.readString();
        video_link = in.readString();
        updated_at = in.readString();
        setId(in.readString());
        List<ImageSet> list = new ArrayList<ImageSet>();
        in.readTypedList(list, ImageSet.CREATOR);
        setImages_links(list);
        cta = in.readParcelable(ContentLink.class.getClassLoader());
        audio = in.readParcelable(Audio.class.getClassLoader());
        upload = in.readParcelable(Upload.class.getClassLoader());
    }

    @Override
    public boolean hasContentToInclude() {
        return audio != null ||
                (images != null && images.size() > 0) ||
                upload != null;
    }
}

@@ -452,16 +452,31 @@
 elable %7B
+%0A%0A    @Nullable
 %0A    @Se
@@ -523,16 +523,30 @@
 title;%0A%0A
+    @Nullable%0A
     @Ser
@@ -602,16 +602,30 @@
 tring;%0A%0A
+    @Nullable%0A
     @Ser
@@ -1140,32 +1140,281 @@
 tent() %7B%0A    %7D%0A%0A
+    @Nullable%0A    public ImageSet getImageLink() %7B%0A        if (images_links == null %7C%7C images_links.isEmpty())%0A            return null;%0A        return images_links.get(0);%0A    %7D%0A%0A    /**%0A     * @deprecated please use %7B@link #getImageLink()%7D%0A     */%0A
     @Deprecated%0A

add nullable and deprecated annotations