package io.github.droidkaigi.confsched2017.viewmodel;

import android.support.annotation.ColorRes;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.support.annotation.VisibleForTesting;

import io.github.droidkaigi.confsched2017.R;
import io.github.droidkaigi.confsched2017.model.Topic;

enum TopicColor {

    PRODUCTIVITY_AND_TOOLING(1, R.color.light_green_alpha_15, R.color.light_green_alpha_50,
            R.color.light_green, R.style.AppTheme_NoActionBar_LightGreen),

    ARCHITECTURE_AND_DEVELOPMENT_PROCESS_METHODOLOGY(2, R.color.yellow_alpha_15, R.color.yellow_alpha_50,
            R.color.yellow, R.style.AppTheme_NoActionBar_Yellow),

    HARDWARE(3, R.color.red_alpha_15, R.color.red_alpha_50,
            R.color.red, R.style.AppTheme_NoActionBar_Red),

    UI_AND_DESIGN(4, R.color.blue_alpha_15, R.color.blue_alpha_50,
            R.color.blue, R.style.AppTheme_NoActionBar_Blue),

    QUALITY_AND_SUSTAINABILITY(5, R.color.light_blue_alpha_15, R.color.light_blue_alpha_50,
            R.color.light_blue, R.style.AppTheme_NoActionBar_LightBlue),

    PLATFORM(6, R.color.pink_alpha_15, R.color.pink_alpha_50,
            R.color.pink, R.style.AppTheme_NoActionBar_Pink),

    OTHER(7, R.color.purple_alpha_15, R.color.purple_alpha_50,
            R.color.purple, R.style.AppTheme_NoActionBar_Purple),

    NONE(0, R.color.purple_alpha_15, R.color.purple_alpha_50,
            R.color.purple, R.style.AppTheme_NoActionBar_Purple);

    @VisibleForTesting int topicId;

    @ColorRes
    public int paleColorResId;

    @ColorRes
    public int middleColorResId;

    @ColorRes
    public int vividColorResId;

    @StyleRes
    public int themeId;

    TopicColor(int topicId, @ColorRes int paleColorResId, @ColorRes int middleColorResId,
            @ColorRes int vividColorResId, @StyleRes int themeId) {
        this.topicId = topicId;
        this.paleColorResId = paleColorResId;
        this.middleColorResId = middleColorResId;
        this.vividColorResId = vividColorResId;
        this.themeId = themeId;
    }

    public static TopicColor from(@Nullable Topic topic) {
        if (topic == null) {
            return NONE;
        } else if (PRODUCTIVITY_AND_TOOLING.topicId == topic.id) {
            return PRODUCTIVITY_AND_TOOLING;
        } else if (ARCHITECTURE_AND_DEVELOPMENT_PROCESS_METHODOLOGY.topicId == topic.id) {
            return ARCHITECTURE_AND_DEVELOPMENT_PROCESS_METHODOLOGY;
        } else if (HARDWARE.topicId == topic.id) {
            return HARDWARE;
        } else if (UI_AND_DESIGN.topicId == topic.id) {
            return UI_AND_DESIGN;
        } else if (QUALITY_AND_SUSTAINABILITY.topicId == topic.id) {
            return QUALITY_AND_SUSTAINABILITY;
        } else if (PLATFORM.topicId == topic.id) {
            return PLATFORM;
        } else if (OTHER.topicId == topic.id) {
            return OTHER;
        } else {
            return NONE;
        }
    }

}

@@ -339,25 +339,205 @@
 c;%0A%0A
-enum TopicColor %7B
+/**%0A * Topic ID corresponds to the order of enum.%0A */%0Aenum TopicColor %7B%0A%0A    NONE(R.color.purple_alpha_15, R.color.purple_alpha_50,%0A            R.color.purple, R.style.AppTheme_NoActionBar_Purple),
 %0A%0A  
@@ -567,11 +567,8 @@
 ING(
-1, 
 R.co
@@ -756,11 +756,8 @@
 OGY(
-2, 
 R.co
@@ -886,11 +886,8 @@
 ARE(
-3, 
 R.co
@@ -1009,11 +1009,8 @@
 IGN(
-4, 
 R.co
@@ -1145,19 +1145,16 @@
 ABILITY(
-5, 
 R.color.
@@ -1294,11 +1294,8 @@
 ORM(
-6, 
 R.co
@@ -1413,140 +1413,8 @@
 HER(
-7, R.color.purple_alpha_15, R.color.purple_alpha_50,%0A            R.color.purple, R.style.AppTheme_NoActionBar_Purple),%0A%0A    NONE(0, 
 R.co
@@ -1762,21 +1762,8 @@
 lor(
-int topicId, 
 @Col
@@ -1911,23 +1911,25 @@
 picId = 
-topicId
+ordinal()
 ;%0A      
@@ -2231,619 +2231,169 @@
    %7D
- else if (PRODUCTIVITY_AND_TOOLING.topicId == topic.id) %7B%0A            return PRODUCTIVITY_AND_TOOLING;%0A        %7D else if (ARCHITECTURE_AND_DEVELOPMENT_PROCESS_METHODOLOGY.topicId == topic.id) %7B%0A            return ARCHITECTURE_AND_DEVELOPMENT_PROCESS_METHODOLOGY;%0A        %7D else if (HARDWARE.topicId == topic.id) %7B%0A            return HARDWARE;%0A        %7D else if (UI_AND_DESIGN.
+%0A        if (topic.id %3C 0) %7B%0A            return NONE;%0A        %7D%0A        if (
 topic
-Id == t
+.id %3E= T
 opic
-.id) %7B%0A            return UI_AND_DESIGN;%0A        %7D else if (QUALITY_AND_SUSTAINABILITY.topicId == topic.id) %7B%0A            return QUALITY_AND_SUSTAINABILITY;%0A        %7D else if (PLATFORM.topicId == topic.id) %7B%0A   
+Color.values().length) %7B%0A            return NONE;%0A        %7D%0A
         
  ret
@@ -2392,157 +2392,50 @@
     
- 
 return 
-PLATFORM;%0A        %7D else if (OTHER.topicId == topic.id) %7B%0A            return OTHER;%0A        %7D else %7B%0A            return NONE;%0A        %7D%0A    %7D%0A
+TopicColor.values()%5Btopic.id%5D;%0A    %7D
 %0A%7D%0A

Use order as topic id.