package com.marverenic.music.instances;

import android.os.Parcel;
import android.os.Parcelable;

public class PlaylistRule implements Parcelable {

    public static final class Type {
        public static final int PLAYLIST = 0;
        public static final int SONG = 1;
        public static final int ARTIST = 2;
        public static final int ALBUM = 3;
        public static final int GENRE = 4;
    }

    public static final class Field {
        public static final int ID = 5;
        public static final int NAME = 6;
        public static final int PLAY_COUNT = 7;
        public static final int SKIP_COUNT = 8;
        public static final int YEAR = 9;
        public static final int DATE_ADDED = 10;
        public static final int DATE_PLAYED = 11;
    }

    public static final class Match {
        public static final int EQUALS = 12;
        public static final int NOT_EQUALS = 13;
        public static final int CONTAINS = 14;
        public static final int NOT_CONTAINS = 15;
        public static final int LESS_THAN = 16;
        public static final int GREATER_THAN = 17;
    }

    private int type;
    private int match;
    private int field;
    private String value;

    private PlaylistRule(int type, int field, int match, String value) {
        this.type = type;
        this.field = field;
        this.match = match;
        this.value = value;
    }

    public PlaylistRule(PlaylistRule rule) {
        this(rule.type, rule.field, rule.match, rule.value);
    }

    private PlaylistRule(Parcel in) {
        type = in.readInt();
        match = in.readInt();
        field = in.readInt();
        value = in.readString();
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof PlaylistRule)) {
            return false;
        }
        if (this == o) {
            return true;
        }
        PlaylistRule other = (PlaylistRule) o;
        return this.type == other.type && this.field == other.field && this.match == other.match
                && this.value.equals(other.value);
    }

    @Override
    public int hashCode() {
        int result = type;
        result = 31 * result + match;
        result = 31 * result + field;
        result = 31 * result + value.hashCode();
        return result;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(type);
        dest.writeInt(match);
        dest.writeInt(field);
        dest.writeString(value);
    }

    public static final Creator<PlaylistRule> CREATOR = new Creator<PlaylistRule>() {
        public PlaylistRule createFromParcel(Parcel in) {
            return new PlaylistRule(in);
        }

        public PlaylistRule[] newArray(int size) {
            return new PlaylistRule[size];
        }
    };
}

@@ -89,16 +89,58 @@
 celable;
+%0Aimport android.support.annotation.IntDef;
 %0A%0Apublic
@@ -188,49 +188,8 @@
  %7B%0A%0A
-    public static final class Type %7B%0A    
     
@@ -226,28 +226,24 @@
 ST = 0;%0A    
-    
 public stati
@@ -264,28 +264,24 @@
 NG = 1;%0A    
-    
 public stati
@@ -304,28 +304,24 @@
 ST = 2;%0A    
-    
 public stati
@@ -343,28 +343,24 @@
 UM = 3;%0A    
-    
 public stati
@@ -385,58 +385,10 @@
 = 4;
-%0A    %7D
 %0A%0A
-    public static final class Field %7B%0A    
     
@@ -419,20 +419,16 @@
 ID = 5;%0A
-    
     publ
@@ -457,28 +457,24 @@
 ME = 6;%0A    
-    
 public stati
@@ -501,28 +501,24 @@
 NT = 7;%0A    
-    
 public stati
@@ -545,28 +545,24 @@
 NT = 8;%0A    
-    
 public stati
@@ -583,20 +583,16 @@
 AR = 9;%0A
-    
     publ
@@ -628,28 +628,24 @@
 D = 10;%0A    
-    
 public stati
@@ -673,22 +673,16 @@
 ED = 11;
-%0A    %7D
 %0A%0A    pu
@@ -703,26 +703,25 @@
 nal 
-class Match %7B%0A    
+int EQUALS = 12;%0A
     
@@ -736,32 +736,36 @@
 tatic final int 
+NOT_
 EQUALS = 12;%0A   
@@ -758,23 +758,19 @@
 UALS = 1
-2
+3
 ;%0A
-    
     publ
@@ -793,33 +793,27 @@
 int 
-NOT_EQUAL
+CONTAIN
 S = 1
-3
+4
 ;%0A    
-    
 publ
@@ -824,32 +824,36 @@
 tatic final int 
+NOT_
 CONTAINS = 14;%0A 
@@ -848,23 +848,19 @@
 AINS = 1
-4
+5
 ;%0A
-    
     publ
@@ -879,39 +879,32 @@
 nal int 
-NOT_CONTAINS
+LESS_THAN
  = 1
-5
+6
 ;%0A
-    
     publ
@@ -915,36 +915,39 @@
 tatic final int 
-LESS
+GREATER
 _THAN = 16;%0A    
@@ -939,23 +939,203 @@
 THAN = 1
-6;
+7;%0A
 %0A    
+@IntDef(value = %7BPLAYLIST, SONG, ARTIST, ALBUM, GENRE%7D)%0A    public @interface Type %7B%0A    %7D%0A%0A    @IntDef(value = %7BID, NAME, PLAY_COUNT, SKIP_COUNT, YEAR, DATE_ADDED, DATE_PLAYED%7D)%0A
     publ
@@ -1141,43 +1141,154 @@
 lic 
-static final int GREATER_THAN = 17;
+@interface Field %7B%0A    %7D%0A%0A    @IntDef(value = %7BEQUALS, NOT_EQUALS, CONTAINS, NOT_CONTAINS, LESS_THAN, GREATER_THAN%7D)%0A    public @interface Match %7B
 %0A   

Create int defs annotations for match types