package com.thebluealliance.androidclient.types;

import com.thebluealliance.androidclient.R;

import android.support.annotation.StringRes;

public enum MatchType {
    NONE,
    QUAL {
        @Override
        public MatchType previous() {
            return null; // see below for options for this line
        }
    },
    OCTO,
    QUARTER,
    SEMI,
    FINAL {
        @Override
        public MatchType next() {
            return null; // see below for options for this line
        }
    };

    public MatchType next() {
        // No bounds checking required here, because the last instance overrides
        return values()[ordinal() + 1];
    }

    public MatchType previous() {
        // No bounds checking required here, because the last instance overrides
        return values()[ordinal() - 1];
    }

    public MatchType get(String str) {
        return valueOf(str);
    }

    public @StringRes int getTypeName() {
        switch (this) {
            case QUAL: return R.string.match_type_qual;
            case OCTO: return R.string.match_type_octo;
            case QUARTER: return R.string.match_type_quarter;
            case SEMI: return R.string.match_type_semis;
            case FINAL: return R.string.match_type_finals;
            default: return R.string.match_type_unknown;
        }
    }

    public @StringRes int getTypeAbbreviation() {
        switch (this) {
            case QUAL: return R.string.match_abbrev_qual;
            case OCTO: return R.string.match_abbrev_octo;
            case QUARTER: return R.string.match_abbrev_quarter;
            case SEMI: return R.string.match_abbrev_semi;
            case FINAL: return R.string.match_abbrev_final;
            default: return R.string.match_abbrev_unknown;
        }
    }

    public int getPlayOrder() {
        switch (this) {
            case QUAL: return 1;
            case OCTO: return 2;
            case QUARTER: return 3;
            case SEMI: return 4;
            case FINAL: return 5;
            default: return 0;
        }
    }

    public static MatchType fromShortType(String str) {
        switch (str) {
            case "qm":
                return QUAL;
            case "ef":
                return OCTO;
            case "qf":
                return QUARTER;
            case "sf":
                return SEMI;
            case "f":
                return FINAL;
            default:
                throw new IllegalArgumentException("Invalid short type");
        }
    }

    public static MatchType fromKey(String key) {
        if (key.contains("_qm")) return QUAL;
        if (key.contains("_qf")) return QUARTER;
        if (key.contains("_ef")) return OCTO;
        if (key.contains("_sf")) return SEMI;
        if (key.contains("_f")) return FINAL;
        return NONE;
    }
}

@@ -170,18 +170,138 @@
 NONE
-,%0A    QUAL
+(R.string.match_type_unknown, R.string.match_abbrev_unknown, 0),%0A    QUAL(R.string.match_type_qual, R.string.match_abbrev_qual, 1)
  %7B%0A 
@@ -448,1717 +448,1356 @@
 OCTO
-,%0A    QUARTER,%0A    SEMI,%0A    FINAL %7B%0A        @Override%0A        public MatchType next() %7B%0A            return null; // see below for options for this line%0A        %7D%0A    %7D;%0A%0A    public MatchType next() %7B%0A        // No bounds checking required here, because the last instance overrides%0A        return values()%5Bordinal() + 1%5D;%0A    %7D%0A%0A    public MatchType previous() %7B%0A        // No bounds checking required here, because the last instance overrides%0A        return values()%5Bordinal() - 1%5D;%0A    %7D%0A%0A    public MatchType get(String str) %7B%0A        return valueOf(str);%0A    %7D%0A%0A    public @StringRes int getTypeName() %7B%0A        switch (this) %7B%0A            case QUAL: return R.string.match_type_qual;%0A            case OCTO: return R.string.match_type_octo;%0A            case QUARTER: return R.string.match_type_quarter;%0A            case SEMI: return R.string.match_type_semis;%0A            case FINAL: return R.string.match_type_finals;%0A            default: return R.string.match_type_unknown;%0A        %7D%0A    %7D%0A%0A    public @StringRes int getTypeAbbreviation() %7B%0A        switch (this) %7B%0A            case QUAL: return R.string.match_abbrev_qual;%0A            case OCTO: return R.string.match_abbrev_octo;%0A            case QUARTER: return R.string.match_abbrev_quarter;%0A            case SEMI: return R.string.match_abbrev_semi;%0A            case FINAL: return R.string.match_abbrev_final;%0A            default: return R.string.match_abbrev_unknown;%0A        %7D%0A    %7D%0A%0A    public int getPlayOrder() %7B%0A        switch (this) %7B%0A            case QUAL: return 1;%0A            case OCTO: return 2;%0A            case QUARTER: return 3;%0A            case SEMI: return 4;%0A            case FINAL: return 5;%0A            default: return 0;%0A        %7D
+(R.string.match_type_octo, R.string.match_abbrev_octo, 2),%0A    QUARTER(R.string.match_type_quarter, R.string.match_abbrev_quarter, 3),%0A    SEMI(R.string.match_type_semis, R.string.match_abbrev_semi, 4),%0A    FINAL(R.string.match_type_finals, R.string.match_abbrev_final, 5) %7B%0A        @Override%0A        public MatchType next() %7B%0A            return null; // see below for options for this line%0A        %7D%0A    %7D;%0A%0A    public @StringRes int typeName;%0A    public @StringRes int typeAbbreviation;%0A    public int playOrder;%0A%0A    MatchType(@StringRes int typeName, @StringRes int typeAbbreviation, int playOrder) %7B%0A        this.typeName = typeName;%0A        this.typeAbbreviation = typeAbbreviation;%0A        this.playOrder = playOrder;%0A    %7D%0A%0A    public MatchType next() %7B%0A        // No bounds checking required here, because the last instance overrides%0A        return values()%5Bordinal() + 1%5D;%0A    %7D%0A%0A    public MatchType previous() %7B%0A        // No bounds checking required here, because the last instance overrides%0A        return values()%5Bordinal() - 1%5D;%0A    %7D%0A%0A    public MatchType get(String str) %7B%0A        return valueOf(str);%0A    %7D%0A%0A    public @StringRes int getTypeName() %7B%0A        return typeName;%0A    %7D%0A%0A    public @StringRes int getTypeAbbreviation() %7B%0A        return typeAbbreviation;%0A    %7D%0A%0A    public int getPlayOrder() %7B%0A        return playOrder;
 %0A   

Clean up MatchType enum resources