package com.alexstyl.specialdates.events;

import android.support.annotation.ColorRes;
import android.support.annotation.StringRes;

import com.alexstyl.specialdates.R;

import java.util.HashMap;
import java.util.Map;

public enum EventType {
    BIRTHDAY(EventColumns.TYPE_BIRTHDAY, R.string.birthday, R.color.birthday_red),
    NAMEDAY(EventColumns.TYPE_NAMEDAY, R.string.nameday, R.color.nameday_blue);

    private static final Map<Integer, EventType> map;

    static {
        map = new HashMap<>();
        for (EventType eventType : values()) {
            map.put(eventType.id, eventType);
        }
    }

    private final int id;
    private final int eventNameRes;
    private final int eventColorRes;

    EventType(@EventTypeId int id, @StringRes int nameResId, @ColorRes int colorResId) {
        this.id = id;
        this.eventNameRes = nameResId;
        this.eventColorRes = colorResId;
    }

    @StringRes
    public int nameRes() {
        return eventNameRes;
    }

    @ColorRes
    public int getColorRes() {
        return eventColorRes;
    }

    public static EventType fromId(@EventTypeId int eventTypeId) {
        if (map.containsKey(eventTypeId)) {
            return map.get(eventTypeId);
        }
        throw new IllegalArgumentException("No event type with id " + eventTypeId);
    }
}

@@ -455,16 +455,125 @@
 %3E map;%0A%0A
+    private final int eventTypeId;%0A    private final int eventNameRes;%0A    private final int eventColorRes;%0A%0A
     stat
@@ -685,17 +685,26 @@
 entType.
-i
+eventTypeI
 d, event
@@ -736,101 +736,263 @@
    p
-rivate final int id;%0A    private final int eventNameRes;%0A    private final int eventColorRes;
+ublic static EventType fromId(@EventTypeId int eventTypeId) %7B%0A        if (map.containsKey(eventTypeId)) %7B%0A            return map.get(eventTypeId);%0A        %7D%0A        throw new IllegalArgumentException(%22No event type with eventTypeId %22 + eventTypeId);%0A    %7D
 %0A%0A  
@@ -1020,17 +1020,26 @@
 eId int 
-i
+eventTypeI
 d, @Stri
@@ -1104,14 +1104,32 @@
 his.
-id = i
+eventTypeId = eventTypeI
 d;%0A 
@@ -1376,260 +1376,7 @@
    %7D
-%0A%0A    public static EventType fromId(@EventTypeId int eventTypeId) %7B%0A        if (map.containsKey(eventTypeId)) %7B%0A            return map.get(eventTypeId);%0A        %7D%0A        throw new IllegalArgumentException(%22No event type with id %22 + eventTypeId);%0A    %7D
 %0A%7D%0A

Move fields to top and give explicit name to id