package org.hisp.dhis.android.core.trackedentity;

import android.support.annotation.Nullable;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class TeiQuery {

    private final int page;
    private final int pageSize;
    private final boolean paging;
    private final Set<String> orgUnits;
    private final int pageLimit;

    @Nullable
    private final Set<String> uIds;


    public TeiQuery(boolean paging, int page, int pageSize,
                    Set<String> orgUnits, int pageLimit) {
        this.paging = paging;
        this.page = page;
        this.pageSize = pageSize;
        this.orgUnits = orgUnits;
        this.pageLimit = pageLimit;
        uIds = null;
    }

    public TeiQuery(boolean paging, int page, int pageSize,
                    Set<String> orgUnits, @Nullable Set<String> uIds, int pageLimit) {
        this.paging = paging;
        this.page = page;
        this.pageSize = pageSize;
        this.orgUnits = orgUnits;
        this.uIds = uIds;
        this.pageLimit = pageLimit;
    }

    @Nullable
    public Set<String> getUIds() {
        return uIds;
    }

    public int getPage() {
        return page;
    }

    public int getPageSize() {
        return pageSize;
    }

    public boolean isPaging() {
        return paging;
    }

    public Set<String> getOrgUnits() {
        return orgUnits;
    }

    public int getPageLimit() {
        return pageLimit;
    }

    public static class Builder {
        private int page = 1;
        private int pageSize = 50;
        private boolean paging;
        private Set<String> orgUnits;
        int pageLimit = 50;

        private Set<String> uIds = new HashSet<>();

        private Builder() {
        }

        public static TeiQuery.Builder create() {
            return new TeiQuery.Builder();
        }

        public TeiQuery.Builder withPaging(boolean paging) {
            this.paging = paging;
            return this;
        }

        public TeiQuery.Builder withPage(int page) {
            this.page = page;
            return this;
        }

        public TeiQuery.Builder withPageSize(int pageSize) {
            this.pageSize = pageSize;
            return this;
        }

        public TeiQuery.Builder withOrgUnits(Set<String> orgUnits) {
            this.orgUnits = orgUnits;
            return this;
        }

        public TeiQuery.Builder withUIds(Set<String> uIds) {
            this.uIds = uIds;
            return this;
        }

        public TeiQuery.Builder withPageLimit(int pageLimit) {
            this.pageLimit = pageLimit;
            return this;
        }

        public TeiQuery build() {
            if (pageLimit > pageSize) {
                throw new IllegalArgumentException(
                        "pageLimit can not be more greater than pageSize");
            }

            return new TeiQuery(paging, page, pageSize,
                    orgUnits, uIds, pageLimit);
        }
    }
}

@@ -100,26 +100,52 @@
 ort 
-java.util.HashSet;
+org.hisp.dhis.android.core.data.api.OuMode;%0A
 %0Aimp
@@ -162,11 +162,14 @@
 til.
-Lis
+HashSe
 t;%0Ai
@@ -381,16 +381,49 @@
 geLimit;
+%0A    private final OuMode ouMode;
 %0A%0A    @N
@@ -527,36 +527,16 @@
 ageSize,
-%0A                   
  Set%3CStr
@@ -555,32 +555,47 @@
 s, int pageLimit
+, OuMode ouMode
 ) %7B%0A        this
@@ -734,32 +734,62 @@
 it = pageLimit;%0A
+        this.ouMode = ouMode;%0A
         uIds = n
@@ -935,32 +935,47 @@
 s, int pageLimit
+, OuMode ouMode
 ) %7B%0A        this
@@ -1140,32 +1140,62 @@
 it = pageLimit;%0A
+        this.ouMode = ouMode;%0A
     %7D%0A%0A    @Null
@@ -1434,32 +1434,94 @@
  paging;%0A    %7D%0A%0A
+    public OuMode getOuMode() %7B%0A        return ouMode;%0A    %7D%0A%0A
     public Set%3CS
@@ -1836,16 +1836,57 @@
 it = 50;
+%0A        OuMode ouMode = OuMode.SELECTED;
 %0A%0A      
@@ -2861,32 +2861,162 @@
 his;%0A        %7D%0A%0A
+        public TeiQuery.Builder withOuMode(OuMode ouMode) %7B%0A            this.ouMode = ouMode;%0A            return this;%0A        %7D%0A%0A
         public T
@@ -3271,36 +3271,16 @@
 ageSize,
-%0A                   
  orgUnit
@@ -3297,16 +3297,24 @@
 ageLimit
+, ouMode
 );%0A     

add OuMode on TeiQuery