package net.dean.jraw.models;

import org.codehaus.jackson.JsonNode;

import java.awt.*;

/**
 * This class represents a Subreddit such as /r/pics.
 */
public class Subreddit extends Thing {

    /**
     * Instantiates a new Subreddit
     *
     * @param dataNode The node to parse data from
     */
    public Subreddit(JsonNode dataNode) {
        super(dataNode);
    }

    /**
     * Gets the amount of users active in the last 15 minutes
     * @return The number of active users
     */
    @JsonProperty
    public Integer getAccountsActive() {
        return data("accounts_active", Integer.class);
    }

    /**
     * Gets the number of minutes the subreddit initially hides comment scores
     * @return The number of minutes the subreddit initially hides comment scores
     */
    @JsonProperty
    public Integer getCommentScoreHideDuration() {
        return data("comment_score_hide_mins", Integer.class);
    }

    /**
     * Gets the subreddit's description
     * @return The subreddit's description
     */
    @JsonProperty
    public RenderStringPair getSidebar() {
        return data("description", RenderStringPair.class);
    }

    /**
     * Gets the "human" name of the subreddit (ex: "pics")
     * @return The subreddit's name
     */
    @JsonProperty
    public String getDisplayName() {
        return data("display_name");
    }

    /**
     * Gets the full URL to the header image, or null if one is not present.
     * @return The full URL to the header image
     */
    @JsonProperty(nullable = true)
    public String getHeaderImage() {
        return data("header_img");
    }

    /**
     * Gets the dimensions of the header image, or null if the header does not exist
     * @return The dimensions of the header image
     */
    @JsonProperty(nullable = true)
    public Dimension getHeaderSize() {
        JsonNode node = data.get("header_size");
        if (node.isNull()) {
            return null;
        }
        return new Dimension(node.get(0).asInt(-1), node.get(1).asInt(-1));
    }

    /**
     * Gets the description of the header image shown when the cursor has hovered over it, or null if a header image is
     * not present
     * @return The header image's description
     */
    @JsonProperty(nullable = true)
    public String getHeaderTitle() {
        return data("header_title");
    }

    /**
     * Checks if this subreddit is not safe for work
     * @return If this subreddit is NSFW
     */
    @JsonProperty
    public Boolean isNsfw() {
        return data("over18", Boolean.class);
    }

    /**
     * Gets the public description show in the subreddit search results
     * @return The public description
     */
    @JsonProperty
    public String getPublicDescription() {
        return data("public_description");
    }

    /**
     * Checks if the subreddit's traffic page is publicly accessible
     * @return If the subreddit's traffic page is publicly accessible
     */
    @JsonProperty
    public Boolean isTrafficPublic() {
        return data("public_traffic", Boolean.class);
    }

    /**
     * Gets the amount of users subscribed to this subreddit
     * @return The amount of users subscribed to this subreddit
     */
    @JsonProperty
    public Long getSubscriberCount() {
        return data("subscribers", Long.class);
    }

    /**
     * Checks if this subreddit allows self (text) posts
     * @return If this subreddit allows self posts
     */
    @JsonProperty
    public Boolean isAllowingSelfPosts() {
        String type = data("submission_type");
        return type.equals("self") || type.equals("all");
    }

    /**
     * Checks if this subreddit allows link posts
     * @return If this subreddit allows link posts
     */
    @JsonProperty
    public Boolean isAllowingLinks() {
        String type = data("submission_type");
        return type.equals("link") || type.equals("all");
    }

    /**
     * Gets the subreddit's custom label for the "submit link" button, if any
     * @return The subreddit's custom label for the "submit link" button
     */
    @JsonProperty
    public String getSubmitLinkLabel() {
        return data("submit_link_label");
    }

    /**
     * Gets the subreddit's custom label for the "submit text" button, if any
     * @return The subreddit's custom label for the "submit link" button
     */
    @JsonProperty
    public String getSubmitTextLabel() {
        return data("submit_text_label");
    }

    /**
     * Gets this subreddit's type
     * @return This subreddit's type
     */
    @JsonProperty
    public Type getSubredditType() {
        return Type.valueOf(data("subreddit_type").toUpperCase());
    }

    /**
     * Gets the title of the main page
     * @return The title of the main page
     */
    @JsonProperty
    public String getTitle() {
        return data("title");
    }

    /**
     * Gets the relative URL of the subreddit (ex: "/r/pics")
     * @return The relative URL of the subreddit
     */
    @JsonProperty
    public String getRelativeLocation() {
        return data("url");
    }

    /**
     * Checks if the logged-in-user is banned from this subreddit
     * @return If the logged-in-user is banned form this subreddit
     */
    @JsonProperty
    public Boolean isUserBanned() {
        return data("user_is_banned", Boolean.class);
    }

    /**
     * Checks if the logged-in-user contributes to this subreddit
     * @return If the logged-in-user contributes to this subreddit
     */
    @JsonProperty
    public Boolean isUserContributor() {
        return data("user_is_contributor", Boolean.class);
    }

    /**
     * Checks if the logged-in-user is a moderator of this subreddit
     * @return If the logged-in-user is a moderator of this subreddit
     */
    @JsonProperty
    public Boolean isUserModerator() {
        return data("user_is_moderator", Boolean.class);
    }

    /**
     * Checks if the logged-in-user is subscribed to this subreddit
     * @return If the logged-in-user is subscribed to this subreddit
     */
    @JsonProperty
    public Boolean isUserSubscriber() {
        return data("user_is_subscriber", Boolean.class);
    }

    /**
     * This class represents a list of all the available subreddit types
     */
    public static enum Type {
        /** Open to all users */
        PUBLIC,
        /** only approved members can view and submit */
        PRIVATE,
        /** Anyone can view, but only some are approved to submit links */
        RESTRICTED,
        /** Only users with Reddit gold can post */
        GOLD_RESTRICTED,
        ARCHIVED
    }

    @Override
    public ThingType getType() {
        return ThingType.SUBREDDIT;
    }
}

@@ -3349,57 +3349,76 @@
   * 
-Checks if this subreddit allows self (text) posts
+Gets the types of submissions allowed to be posted on this subreddit
 %0A   
@@ -3506,56 +3506,80 @@
 lic 
-Boolean isAllowingSelfPosts() %7B%0A        String t
+SubmissionType getAllowedSubmissionType() %7B%0A        JsonNode submissionT
 ype 
@@ -3576,32 +3576,36 @@
 ssionType = data
+.get
 (%22submission_typ
@@ -3621,341 +3621,164 @@
     
-return type.equals(%22self%22) %7C%7C type.equals(%22all%22);%0A    %7D%0A
+if (submissionType.isNull()) %7B
 %0A    
-/**%0A
      
-* Checks if this subreddit allows link posts%0A     * @return If this subreddit allows link posts%0A     */%0A    @JsonProperty%0A    public Boolean isAllowingLinks() %7B%0A        String type = data(%22submission_type%22);%0A        return type.equals(%22link%22) %7C%7C type.equals(%22all%22
+   return SubmissionType.NONE;%0A        %7D%0A        return SubmissionType.valueOf(submissionType.asText().toUpperCase()
 );%0A 
@@ -6478,24 +6478,254 @@
 IVED%0A    %7D%0A%0A
+    public static enum SubmissionType %7B%0A        /** Links and self posts */%0A        ANY,%0A        /** Only links */%0A        LINK,%0A        /** Only self posts */%0A        SELF,%0A        /** Restricted subreddit */%0A        NONE%0A    %7D%0A%0A
     @Overrid

Combine isAllowingSelfPosts() and isAllowingLinks()