package com.vishnus1224.teamworkapidemo.repository;

import com.vishnus1224.teamworkapidemo.manager.RealmManager;
import com.vishnus1224.teamworkapidemo.mapper.RealmResultToListMapper;
import com.vishnus1224.teamworkapidemo.model.LatestActivityModel;

import java.util.List;

import javax.inject.Inject;

import io.realm.Realm;
import io.realm.RealmResults;
import rx.Observable;

/**
 * Created by Vishnu on 8/29/2016.
 */
public class LatestActivityRealmRepository implements BaseRepository<LatestActivityModel> {

    private RealmManager realmManager;

    private RealmResultToListMapper realmResultToListMapper;

    @Inject
    public LatestActivityRealmRepository(RealmManager realmManager, RealmResultToListMapper realmResultToListMapper) {

        this.realmManager = realmManager;

        this.realmResultToListMapper = realmResultToListMapper;

    }

    @Override
    public void add(final LatestActivityModel latestActivityModel) {

        realmManager.addToRealm(latestActivityModel);

    }

    @Override
    public void addAll(final List<LatestActivityModel> latestActivityModels) {

        realmManager.addAllToRealm(latestActivityModels);

    }

    @Override
    public LatestActivityModel removeItem() {
        return null;
    }

    @Override
    public Observable<LatestActivityModel> getItem() {
        return null;
    }

    @Override
    public Observable<List<LatestActivityModel>> getAllItems() {

        Realm realm = realmManager.newRealm();

        RealmResults<LatestActivityModel> realmResults = realm.where(LatestActivityModel.class).findAll();

        Observable<List<LatestActivityModel>> observable = Observable.just(realmResultToListMapper.map(realmResults));

        return observable;
    }
}

@@ -153,39 +153,181 @@
 .mapper.
-RealmResultToListMapper
+LatestActivityDtoToModelMapper;%0Aimport com.vishnus1224.teamworkapidemo.mapper.RealmResultToListMapper;%0Aimport com.vishnus1224.teamworkapidemo.model.LatestActivityDto
 ;%0Aimport
@@ -387,16 +387,44 @@
 Model;%0A%0A
+import java.util.ArrayList;%0A
 import j
@@ -670,21 +670,19 @@
 Activity
-Model
+Dto
 %3E %7B%0A%0A   
@@ -776,24 +776,100 @@
 istMapper;%0A%0A
+    private LatestActivityDtoToModelMapper latestActivityDtoToModelMapper;%0A%0A
     @Inject%0A
@@ -983,16 +983,120 @@
 stMapper
+,%0A                                         LatestActivityDtoToModelMapper latestActivityDtoToModelMapper
 ) %7B%0A%0A   
@@ -1196,24 +1196,103 @@
 istMapper;%0A%0A
+        this.latestActivityDtoToModelMapper = latestActivityDtoToModelMapper;%0A%0A
     %7D%0A%0A    @
@@ -1340,21 +1340,19 @@
 Activity
-Model
+Dto
  latestA
@@ -1358,21 +1358,19 @@
 Activity
-Model
+Dto
 ) %7B%0A%0A   
@@ -1412,21 +1412,55 @@
 Activity
-Model
+DtoToModelMapper.map(latestActivityDto)
 );%0A%0A    
@@ -1528,38 +1528,328 @@
 vity
-Model%3E latestActivityModels) %7B
+Dto%3E latestActivityDtoList) %7B%0A%0A        List%3CLatestActivityModel%3E latestActivityModelList = new ArrayList%3C%3E(latestActivityDtoList.size());%0A%0A        for(LatestActivityDto latestActivityDto : latestActivityDtoList)%7B%0A%0A            latestActivityModelList.add(latestActivityDtoToModelMapper.map(latestActivityDto));%0A%0A        %7D
 %0A%0A  
@@ -1900,17 +1900,20 @@
 ityModel
-s
+List
 );%0A%0A    
@@ -1954,21 +1954,19 @@
 Activity
-Model
+Dto
  removeI
@@ -2051,21 +2051,19 @@
 Activity
-Model
+Dto
 %3E getIte
@@ -2151,21 +2151,19 @@
 Activity
-Model
+Dto
 %3E%3E getAl
@@ -2368,21 +2368,19 @@
 Activity
-Model
+Dto
 %3E%3E obser

set the data type to latest activity dto