package com.marverenic.music.instances;

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.IntDef;

public class PlaylistRule implements Parcelable {

    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 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 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;

    @IntDef(value = {PLAYLIST, SONG, ARTIST, ALBUM, GENRE})
    public @interface Type {
    }

    @IntDef(value = {ID, NAME, PLAY_COUNT, SKIP_COUNT, YEAR, DATE_ADDED, DATE_PLAYED})
    public @interface Field {
    }

    @IntDef(value = {EQUALS, NOT_EQUALS, CONTAINS, NOT_CONTAINS, LESS_THAN, GREATER_THAN})
    public @interface Match {
    }

    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];
        }
    };
}

@@ -38,34 +38,8 @@
 s;%0A%0A
-import android.os.Parcel;%0A
 impo
@@ -107,22 +107,107 @@
 ntDef;%0A%0A
-public
+import com.marverenic.music.data.store.MusicStore;%0A%0Aimport java.util.List;%0A%0Apublic abstract
  class P
@@ -1358,25 +1358,13 @@
     
-private int t
+@T
 ype
-;
 %0A   
@@ -1376,378 +1376,116 @@
 ate 
+f
 in
-t match;%0A    private int field;%0A    private String value;%0A%0A    private PlaylistRule(int type, int field, int match, String value) %7B%0A        this.type = type;%0A        this.field = f
+al int mType;%0A%0A    @Field%0A    private final int mF
 ield;%0A
+%0A
     
-    this.match = match;%0A        this.value = value;%0A    %7D%0A%0A    public PlaylistRule(PlaylistRule rule) %7B%0A        this(rule.type, rule.field, rule.match, rule.value);%0A    %7D
+@Match%0A    private final int mMatch;
 %0A%0A    pr
 ivat
@@ -1480,21 +1480,23 @@
 %0A%0A    pr
-iva
+otec
 te
+d
  Playlis
@@ -1505,535 +1505,130 @@
 ule(
-Parcel in) %7B%0A        t
+@T
 ype
- =
  in
-.readInt();%0A        match = in.readInt();%0A        field = in.readInt();%0A        value = in.readString();%0A    %7D%0A%0A    @Override%0A    public boolean equals(Object o) %7B%0A        if (!(o instanceof PlaylistRule)) %7B%0A            return false;%0A        %7D%0A        if (this == o) %7B%0A            return true;%0A        %7D%0A        PlaylistRule other = (PlaylistRule) o;%0A        return this.type == other.type && this.field == other.field && this.m
+t type, @Field int field, @Match int match) %7B%0A        mType = type;%0A        mField = field;%0A        mM
 atch =
-= other.match%0A                && this.value.equals(other.value)
+ match
 ;%0A  
@@ -1629,39 +1629,35 @@
 ch;%0A    %7D%0A%0A    @
-Overrid
+Typ
 e%0A    public int
@@ -1661,172 +1661,19 @@
 int 
-hashCode() %7B%0A        int result = type;%0A        result = 31 * result + match;%0A        result = 31 * result + field;%0A        result = 31 * result + value.hashCode();
+getType() %7B
 %0A   
@@ -1688,14 +1688,13 @@
 urn 
-result
+mType
 ;%0A  
@@ -1699,32 +1699,29 @@
     %7D%0A%0A    @
-Override
+Field
 %0A    public 
@@ -1728,24 +1728,16 @@
 int 
-describeContents
+getField
 () %7B
@@ -1752,17 +1752,22 @@
  return 
-0
+mField
 ;%0A    %7D%0A
@@ -1776,16 +1776,13 @@
    @
-Override
+Match
 %0A   
@@ -1793,487 +1793,121 @@
 lic 
-void writeToParcel(Parcel dest, int flags) %7B%0A        dest.writeInt(type);%0A        dest.writeInt(match);%0A        dest.writeInt(field);%0A        dest.writeString(value);%0A    %7D%0A%0A    public static final Creator%3CPlaylistRule%3E CREATOR = new Creator%3CPlaylistRule%3E() %7B%0A        public PlaylistRule createFromParcel(Parcel in) %7B%0A            return new PlaylistRule(in);%0A        %7D%0A%0A        public PlaylistRule%5B%5D newArray(int size) %7B%0A            return new PlaylistRule%5Bsize%5D;%0A        %7D%0A    %7D;
+int getMatch() %7B%0A        return mMatch;%0A    %7D%0A%0A    public abstract List%3CSong%3E applyFilter(MusicStore musicStore);%0A
 %0A%7D%0A

Make PlaylistRule an abstract immutable value type