package com.veyndan.paper.reddit.post;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;

import com.google.auto.value.AutoValue;
import com.veyndan.paper.reddit.R;

import static com.google.common.base.Preconditions.checkState;

@AutoValue
public abstract class Flair {

    public enum Type {
        STICKIED, LOCKED, NSFW, LINK, GILDED
    }

    public static Flair stickied(final Context context) {
        return builder()
                .type(Type.STICKIED)
                .backgroundColor(ContextCompat.getColor(context, R.color.post_flair_stickied))
                .text(context.getString(R.string.post_stickied))
                .build();
    }

    public static Flair locked(final Context context) {
        return builder()
                .type(Type.LOCKED)
                .backgroundColor(ContextCompat.getColor(context, R.color.post_flair_locked))
                .text(context.getString(R.string.post_locked))
                .icon(ContextCompat.getDrawable(context, R.drawable.ic_lock_outline_white_12sp))
                .build();
    }

    public static Flair nsfw(final Context context) {
        return builder()
                .type(Type.NSFW)
                .backgroundColor(ContextCompat.getColor(context, R.color.post_flair_nsfw))
                .text(context.getString(R.string.post_nsfw))
                .searchQuery("nsfw:yes")
                .build();
    }

    public static Flair link(final Context context, final String text) {
        return builder()
                .type(Type.LINK)
                .backgroundColor(ContextCompat.getColor(context, R.color.post_flair_link))
                .text(text)
                .searchQuery(String.format("flair:'%s'", text))
                .build();
    }

    public static Flair gilded(final Context context, final int gildedCount) {
        return builder()
                .type(Type.GILDED)
                .backgroundColor(ContextCompat.getColor(context, R.color.post_flair_gilded))
                .text(String.valueOf(gildedCount))
                .icon(ContextCompat.getDrawable(context, R.drawable.ic_star_white_12sp))
                .build();
    }

    @NonNull
    public abstract Type type();

    public abstract int backgroundColor();

    @Nullable
    public abstract String text();

    @Nullable
    public abstract Drawable icon();

    @Nullable
    public abstract String searchQuery();

    public final boolean searchable() {
        return searchQuery() != null;
    }

    public static Builder builder() {
        return new AutoValue_Flair.Builder();
    }

    @AutoValue.Builder
    abstract static class Builder {

        abstract Builder type(Type type);

        abstract Builder backgroundColor(@ColorInt int backgroundColor);

        abstract Builder text(String text);

        abstract Builder icon(Drawable icon);

        abstract Builder searchQuery(String searchQuery);

        abstract Flair autoBuild();

        final Flair build() {
            final Flair flair = autoBuild();
            checkState(flair.backgroundColor() != 0, "backgroundColor must be set");
            return flair;
        }
    }
}

@@ -156,51 +156,8 @@
 nt;%0A
-import android.support.annotation.NonNull;%0A
 impo
@@ -192,24 +192,24 @@
 n.Nullable;%0A
+
 import andro
@@ -432,83 +432,8 @@
  %7B%0A%0A
-    public enum Type %7B%0A        STICKIED, LOCKED, NSFW, LINK, GILDED%0A    %7D%0A%0A
     
@@ -515,45 +515,8 @@
 r()%0A
-                .type(Type.STICKIED)%0A
     
@@ -789,43 +789,8 @@
 r()%0A
-                .type(Type.LOCKED)%0A
     
@@ -1154,41 +1154,8 @@
 r()%0A
-                .type(Type.NSFW)%0A
     
@@ -1478,41 +1478,8 @@
 r()%0A
-                .type(Type.LINK)%0A
     
@@ -1798,43 +1798,8 @@
 r()%0A
-                .type(Type.GILDED)%0A
     
@@ -2064,55 +2064,8 @@
  %7D%0A%0A
-    @NonNull%0A    public abstract Type type();%0A%0A
     
@@ -2462,16 +2462,16 @@
 Builder%0A
+
     abst
@@ -2503,51 +2503,8 @@
  %7B%0A%0A
-        abstract Builder type(Type type);%0A%0A
     

Remove unused Flair.Type enum