package com.joshuaavalon.wsdeckeditor.config;

import android.support.annotation.NonNull;

import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Multiset;
import com.joshuaavalon.wsdeckeditor.sdk.card.Card;

import java.util.Comparator;

public enum CardOrder {
    Serial(new SerialComparator()), Level(new LevelComparator()), Detail(new DetailComparator());
    @NonNull
    private final Comparator<Multiset.Entry<Card>> comparator;

    CardOrder(@NonNull final Comparator<Multiset.Entry<Card>> comparator) {
        this.comparator = comparator;
    }

    @NonNull
    public Comparator<Multiset.Entry<Card>> getComparator() {
        return comparator;
    }

    private static class SerialComparator implements Comparator<Multiset.Entry<Card>> {
        @Override
        public int compare(Multiset.Entry<Card> o1, Multiset.Entry<Card> o2) {
            return o1.getElement().getSerial().compareTo(o2.getElement().getSerial());
        }
    }

    private static class LevelComparator implements Comparator<Multiset.Entry<Card>> {
        @Override
        public int compare(Multiset.Entry<Card> o1, Multiset.Entry<Card> o2) {
            return o1.getElement().getLevel() - o2.getElement().getLevel();
        }
    }

    private static class DetailComparator implements Comparator<Multiset.Entry<Card>> {
        @Override
        public int compare(Multiset.Entry<Card> o1, Multiset.Entry<Card> o2) {
            final Card left = o1.getElement();
            final Card right = o2.getElement();
            return ComparisonChain.start()
                    .compare(left.getColor().ordinal(), right.getColor().ordinal())
                    .compare(left.getType().ordinal(), right.getType().ordinal())
                    .compare(left.getLevel(), right.getLevel())
                    .compare(left.getSerial(), right.getSerial())
                    .result();
        }
    }
}

@@ -1611,29 +1611,28 @@
 are(left.get
-Color
+Type
 ().ordinal()
@@ -1646,13 +1646,12 @@
 .get
-Color
+Type
 ().o
@@ -1689,36 +1689,37 @@
 compare(left.get
-Type
+Color
 ().ordinal(), ri
@@ -1717,36 +1717,37 @@
 nal(), right.get
-Type
+Color
 ().ordinal())%0A  

Change CardOrder detail