package com.creatubbles.api.model.gallery;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.creatubbles.api.model.partner_application.PartnerApplication;
import com.creatubbles.api.model.user.User;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.jasminb.jsonapi.annotations.Id;
import com.github.jasminb.jsonapi.annotations.Relationship;
import com.github.jasminb.jsonapi.annotations.Type;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Type("galleries")
public class Gallery {

    @Id
    private String id;

    private String name;

    private String description;

    @JsonProperty("open_for_all")
    private boolean openForAll;

    @JsonProperty("created_at")
    private Date createdAt;

    @JsonProperty("updated_at")
    private Date updatedAt;

    @JsonProperty("last_bubbled_at")
    private Date lastBubbledAt;

    @JsonProperty("last_commented_at")
    private Date lastCommentedAt;

    @JsonProperty("creations_count")
    private Integer creationsCount;

    @JsonProperty("bubbles_count")
    private Integer bubblesCount;

    @JsonProperty("comments_count")
    private Integer commentsCount;

    @JsonProperty("short_url")
    private String shortUrl;

    private Banner banner;

    @JsonProperty("preview_image_urls")
    private List<String> previewImageUrls = Collections.emptyList();

    @Relationship("owner")
    private User owner;

    @Relationship("partner_application")
    private PartnerApplication partnerApplication;

    public Gallery(String galleryId) {
        this.id = galleryId;
    }

    @NonNull
    public String getId() {
        return id;
    }

    @NonNull
    public String getName() {
        return name;
    }

    @Nullable
    public String getDescription() {
        return description;
    }

    @JsonCreator
    public Gallery() {
    }

    /**
     *
     * @param name name of the gallery
     * @param description (optional)
     * @param openForAll (optional) value indicating if everyone can sumbit creations to this gallery
     * @param owner (optional) if null then current user is assumed.
     */
    public Gallery(@NonNull String name, @Nullable String description, boolean openForAll, @Nullable User owner) {
        this.name = name;
        this.description = description;
        this.openForAll = openForAll;
        this.owner = owner;
    }

    /**
     * @return boolean indicating if everyone can submit creations to this gallery
     */
    public boolean getOpenForAll() {
        return openForAll;
    }

    @NonNull
    public Date getCreatedAt() {
        return createdAt;
    }

    @NonNull
    public Date getUpdatedAt() {
        return updatedAt;
    }

    @Nullable
    public Date getLastBubbledAt() {
        return lastBubbledAt;
    }

    @Nullable
    public Date getLastCommentedAt() {
        return lastCommentedAt;
    }

    @NonNull
    public Integer getCreationsCount() {
        return creationsCount;
    }

    @NonNull
    public Integer getBubblesCount() {
        return bubblesCount;
    }

    @NonNull
    public Integer getCommentsCount() {
        return commentsCount;
    }

    @NonNull
    public String getShortUrl() {
        return shortUrl;
    }

    @Nullable
    public Banner getBanner() {
        return banner;
    }

    @NonNull
    public List<String> getPreviewImageUrls() {
        return previewImageUrls;
    }

    @NonNull
    public User getOwner() {
        return owner;
    }

    public PartnerApplication getPartnerApplication() {
        return partnerApplication;
    }

    @Override public String toString() {
        return "Gallery{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", description='" + description + '\'' +
                ", openForAll=" + openForAll +
                ", createdAt='" + createdAt + '\'' +
                ", updatedAt='" + updatedAt + '\'' +
                ", lastBubbledAt=" + lastBubbledAt +
                ", lastCommentedAt=" + lastCommentedAt +
                ", creationsCount=" + creationsCount +
                ", bubblesCount=" + bubblesCount +
                ", commentsCount=" + commentsCount +
                ", shortUrl='" + shortUrl + '\'' +
                ", banner=" + banner +
                ", previewImageUrls=" + previewImageUrls +
                ", owner=" + owner +
                ", partnerApplication=" + partnerApplication +
                '}';
    }
}

@@ -1612,24 +1612,144 @@
 plication;%0A%0A
+    @Relationship(%22connected_partner_applications%22)%0A    private List%3CPartnerApplication%3E connectedPartnerApplications;%0A%0A
     public G
@@ -2094,15 +2094,8 @@
 /**%0A
-     *%0A
     
@@ -2109,16 +2109,23 @@
 am name 
+       
 name of 
@@ -2198,16 +2198,17 @@
 nForAll 
+ 
 (optiona
@@ -2296,16 +2296,22 @@
 m owner 
+      
 (optiona
@@ -3726,93 +3726,443 @@
     
-public PartnerApplication getPartnerApplication() %7B%0A        return partnerApplication
+/**%0A     * present if this gallery is original gallery of a partner_application%0A     */%0A    @Nullable%0A    public PartnerApplication getPartnerApplication() %7B%0A        return partnerApplication;%0A    %7D%0A%0A    /**%0A     * list of partner applications this gallery is connected with (includes partner_application above)%0A     */%0A    public List%3CPartnerApplication%3E getConnectedPartnerApplications() %7B%0A        return connectedPartnerApplications
 ;%0A  
@@ -4179,16 +4179,20 @@
 Override
+%0A   
  public 

Add connected partner applications list to gallery model