package com.expidev.gcmapp.model;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

/**
 * Created by matthewfrederick on 1/26/15.
 */
public class Training extends Base
{
    private int id;
    private String ministryId;
    private String name;
    private Date date;
    private String type;
    private String mcc;
    private double latitude;
    private double longitude;
    private List<GCMTrainingCompletions> completions;
    
    public static boolean equals(Training first, Training second)
    {
        // does everything in the object need to be compared?
        
        if (first.getId() != second.getId()) return false;
        if (!first.getName().equals(second.getName())) return false;
        if (!first.getMinistryId().equals(second.getMinistryId())) return false;
        
        return true;
    }

    public int getId()
    {
        return id;
    }

    public void setId(int id)
    {
        this.id = id;
    }

    public String getMinistryId()
    {
        return ministryId;
    }

    public void setMinistryId(String ministryId)
    {
        this.ministryId = ministryId;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public Date getDate()
    {
        return date;
    }

    public void setDate(Date date)
    {
        this.date = date;
    }

    public String getType()
    {
        return type;
    }

    public void setType(String type)
    {
        this.type = type;
    }

    public String getMcc()
    {
        return mcc;
    }

    public void setMcc(String mcc)
    {
        this.mcc = mcc;
    }

    public double getLatitude()
    {
        return latitude;
    }

    public void setLatitude(double latitude)
    {
        this.latitude = latitude;
    }

    public double getLongitude()
    {
        return longitude;
    }

    public void setLongitude(double longitude)
    {
        this.longitude = longitude;
    }

    public List<GCMTrainingCompletions> getCompletions()
    {
        return completions;
    }

    public void setCompletions(List<GCMTrainingCompletions> completions)
    {
        this.completions = completions;
    }

    public static class GCMTrainingCompletions
    {
        private int id;
        private int phase;
        private int numberCompleted;
        private Date date;
        private int trainingId;
        private Timestamp synced;
        
        public static boolean equals(GCMTrainingCompletions first, GCMTrainingCompletions second)
        {
            if (first.getId() != second.getId()) return false;
            if (first.getPhase() != second.getPhase()) return false;
            if (first.getTrainingId() != second.getTrainingId()) return false;

            return true;
        }

        public int getId()
        {
            return id;
        }

        public void setId(int id)
        {
            this.id = id;
        }

        public int getPhase()
        {
            return phase;
        }

        public void setPhase(int phase)
        {
            this.phase = phase;
        }

        public int getNumberCompleted()
        {
            return numberCompleted;
        }

        public void setNumberCompleted(int numberCompleted)
        {
            this.numberCompleted = numberCompleted;
        }

        public Date getDate()
        {
            return date;
        }

        public void setDate(Date date)
        {
            this.date = date;
        }

        public int getTrainingId()
        {
            return trainingId;
        }

        public void setTrainingId(int trainingId)
        {
            this.trainingId = trainingId;
        }

        public Timestamp getSynced()
        {
            return synced;
        }

        public void setSynced(Timestamp synced)
        {
            this.synced = synced;
        }
    }
}

@@ -39,26 +39,172 @@
 ort 
-java.sql.Timestamp
+android.support.annotation.NonNull;%0Aimport android.support.annotation.Nullable;%0A%0Aimport java.sql.Timestamp;%0Aimport java.util.ArrayList;%0Aimport java.util.Collections
 ;%0Aim
@@ -539,24 +539,37 @@
  longitude;%0A
+    @NonNull%0A
     private 
@@ -568,16 +568,22 @@
 private 
+final 
 List%3CGCM
@@ -614,22 +614,38 @@
 pletions
-;%0A    
+ = new ArrayList%3C%3E();%0A
 %0A    pub
@@ -2184,32 +2184,45 @@
 ngitude;%0A    %7D%0A%0A
+    @NonNull%0A
     public List%3C
@@ -2283,16 +2283,45 @@
  return 
+Collections.unmodifiableList(
 completi
@@ -2315,32 +2315,33 @@
 List(completions
+)
 ;%0A    %7D%0A%0A    pub
@@ -2364,16 +2364,32 @@
 letions(
+@Nullable final 
 List%3CGCM
@@ -2421,23 +2421,92 @@
 letions)
+ %7B
 %0A    
-%7B%0A
+    this.completions.clear();%0A        if (completions != null) %7B%0A    
         
@@ -2521,19 +2521,24 @@
 pletions
- = 
+.addAll(
 completi
@@ -2540,17 +2540,28 @@
 pletions
-;
+);%0A        %7D
 %0A    %7D%0A%0A

simplify usage of completions by always returning @NonNull