package pl.temomuko.autostoprace.data.model;

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

import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;

/**
 * Created by Szymon Kozak on 2016-01-22.
 */
public class Team implements Comparable<Team>, Parcelable {

    @SerializedName("team_slug") private String mTeamSlug;
    @SerializedName("name") private String mName;

    @SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
    @SerializedName("last_location")
    private ArrayList<LocationRecord> mLastLocationRecordList;

    @Override
    public int compareTo(@NonNull Team another) {
        return Integer.valueOf(getTeamNumber()).compareTo(another.getTeamNumber());
    }

    public int getTeamNumber() {
        return Integer.valueOf(mTeamSlug.split("-")[1]);
    }

    public String getName() {
        return mName;
    }

    public LocationRecord getLastLocationRecord() {
        return mLastLocationRecordList.isEmpty() ? null : mLastLocationRecordList.get(0);
    }

    /* Parcel */

    protected Team(Parcel in) {
        this.mTeamSlug = in.readString();
        this.mName = in.readString();
        this.mLastLocationRecordList = in.createTypedArrayList(LocationRecord.CREATOR);
    }

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

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.mTeamSlug);
        dest.writeString(this.mName);
        dest.writeTypedList(mLastLocationRecordList);
    }

    public static final Creator<Team> CREATOR = new Creator<Team>() {
        @Override
        public Team createFromParcel(Parcel source) {
            return new Team(source);
        }

        @Override
        public Team[] newArray(int size) {
            return new Team[size];
        }
    };
}

@@ -195,37 +195,8 @@
 e;%0A%0A
-import java.util.ArrayList;%0A%0A
 /**%0A
@@ -327,13 +327,8 @@
 me(%22
-team_
 slug
@@ -409,71 +409,8 @@
 ame;
-%0A%0A    @SuppressWarnings(%22MismatchedQueryAndUpdateOfCollection%22)
 %0A   
@@ -442,20 +442,16 @@
 cation%22)
-%0A   
  private
@@ -455,18 +455,8 @@
 ate 
-ArrayList%3C
 Loca
@@ -465,17 +465,16 @@
 onRecord
-%3E
  mLastLo
@@ -479,26 +479,16 @@
 Location
-RecordList
 ;%0A%0A    @
@@ -877,68 +877,8 @@
 tion
-RecordList.isEmpty() ? null : mLastLocationRecordList.get(0)
 ;%0A  
@@ -940,21 +940,16 @@
         
-this.
 mTeamSlu
@@ -977,21 +977,16 @@
         
-this.
 mName = 
@@ -1010,21 +1010,16 @@
         
-this.
 mLastLoc
@@ -1027,143 +1027,67 @@
 tion
-RecordList
  = in.
-c
 rea
-teTypedArrayList(LocationRecord.CREATOR);%0A    %7D%0A%0A    @Override%0A    public int describeContents() %7B%0A        return 0
+dParcelable(LocationRecord.class.getClassLoader())
 ;%0A  
@@ -1186,21 +1186,16 @@
 eString(
-this.
 mTeamSlu
@@ -1227,13 +1227,8 @@
 ing(
-this.
 mNam
@@ -1253,17 +1253,18 @@
 rite
-TypedList
+Parcelable
 (mLa
@@ -1277,19 +1277,91 @@
 tion
-RecordList)
+, flags);%0A    %7D%0A%0A    @Override%0A    public int describeContents() %7B%0A        return 0
 ;%0A  
@@ -1497,22 +1497,18 @@
 (Parcel 
-source
+in
 ) %7B%0A    
@@ -1535,14 +1535,10 @@
 eam(
-source
+in
 );%0A 

Fix Team model