/*
 * Copyright 2014 Open mHealth
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.openmhealth.shim;

import org.joda.time.DateTime;

import java.time.OffsetDateTime;
import java.util.List;

/**
 * A wrapper for encapsulating data requests sent
 * to shims. Prevents from having long method signatures.
 *
 * @author Danilo Bonilla
 */
public class ShimDataRequest {

    /**
     * Identifier for the type of data being retrieved
     */
    private String dataTypeKey;
    /**
     * parameters required for acessing data, this
     * will likely be oauth token + any extras or some
     * kind of trusted access.
     */
    private AccessParameters accessParameters;

    /**
     * // TODO replace this with filters on effective time, using the Data Point API
     * The start date for the data being retrieved
     */
    private OffsetDateTime startDateTime;

    /**
     * The end date for the data being retrieved
     */
    private OffsetDateTime endDateTime;

    /**
     * List of columns required
     */
    private List<String> columnList;

    /**
     * The starting row for the data (for pagination purposes)
     */
    private Long numToSkip;

    /**
     * Number of rows to return
     */
    private Long numToReturn;

    /**
     * If true, returns normalized results
     * from the external data provider, otherwise
     * returns raw data.
     */
    private boolean normalize = true;

    public ShimDataRequest() {
    }

    public ShimDataRequest(String dataTypeKey,
                           AccessParameters accessParameters,
                           OffsetDateTime startDateTime,
                           OffsetDateTime endDateTime,
                           List<String> columnList,
                           Long numToSkip,
                           Long numToReturn,
                           boolean normalize) {
        this.dataTypeKey = dataTypeKey;
        this.accessParameters = accessParameters;
        this.startDateTime = startDateTime;
        this.endDateTime = endDateTime;
        this.columnList = columnList;
        this.numToSkip = numToSkip;
        this.numToReturn = numToReturn;
        this.normalize = false;
    }

    public void setDataTypeKey(String dataTypeKey) {
        this.dataTypeKey = dataTypeKey;
    }

    public void setAccessParameters(AccessParameters accessParameters) {
        this.accessParameters = accessParameters;
    }

    public OffsetDateTime getStartDateTime() {
        return startDateTime;
    }

    public DateTime getStartDate() {
        return getStartDateTime() == null ? null : new DateTime(getStartDateTime().toInstant());
    }

    public void setStartDateTime(OffsetDateTime startDateTime) {
        this.startDateTime = startDateTime;
    }

    public OffsetDateTime getEndDateTime() {
        return endDateTime;
    }

    public DateTime getEndDate() {
        return getStartDateTime() == null ? null : new DateTime(getStartDateTime().toInstant());
    }

    public void setEndDateTime(OffsetDateTime endDateTime) {
        this.endDateTime = endDateTime;
    }

    public void setColumnList(List<String> columnList) {
        this.columnList = columnList;
    }

    public void setNumToSkip(Long numToSkip) {
        this.numToSkip = numToSkip;
    }

    public void setNumToReturn(Long numToReturn) {
        this.numToReturn = numToReturn;
    }

    public String getDataTypeKey() {
        return dataTypeKey;
    }

    public AccessParameters getAccessParameters() {
        return accessParameters;
    }

    public List<String> getColumnList() {
        return columnList;
    }

    public Long getNumToSkip() {
        return numToSkip;
    }

    public Long getNumToReturn() {
        return numToReturn;
    }

    public boolean getNormalize() {
        return normalize;
    }

    public void setNormalize(boolean normalize) {
        this.normalize = normalize;
    }
}

@@ -707,16 +707,17 @@
 .List;%0A%0A
+%0A
 /**%0A * A
@@ -761,19 +761,16 @@
 sts sent
-%0A *
  to shim
@@ -1043,23 +1043,16 @@
 ta, this
-%0A     *
  will li
@@ -1091,23 +1091,16 @@
  or some
-%0A     *
  kind of
@@ -1107,16 +1107,23 @@
  trusted
+%0A     *
  access.
@@ -1271,23 +1271,16 @@
 oint API
-%0A     *
  The sta
@@ -1297,32 +1297,39 @@
 r the data being
+%0A     *
  retrieved%0A     
@@ -1484,94 +1484,8 @@
 e;%0A%0A
-    /**%0A     * List of columns required%0A     */%0A    private List%3CString%3E columnList;%0A%0A
     
@@ -1717,23 +1717,16 @@
  results
-%0A     *
  from th
@@ -1760,23 +1760,16 @@
 therwise
-%0A     *
  returns
@@ -1911,31 +1911,16 @@
 ypeKey,%0A
-               
         
@@ -1958,31 +1958,16 @@
 meters,%0A
-               
         
@@ -2012,31 +2012,16 @@
         
-          
-     
 OffsetDa
@@ -2052,31 +2052,16 @@
         
-        
-       
 List%3CStr
@@ -2085,39 +2085,24 @@
             
-      
-         
 Long numToSk
@@ -2117,31 +2117,16 @@
         
-    
-           
 Long num
@@ -2135,31 +2135,16 @@
 Return,%0A
-               
         
@@ -2346,46 +2346,8 @@
 me;%0A
-        this.columnList = columnList;%0A
     
@@ -3359,110 +3359,8 @@
  %7D%0A%0A
-    public void setColumnList(List%3CString%3E columnList) %7B%0A        this.columnList = columnList;%0A    %7D%0A%0A
     
@@ -3711,84 +3711,8 @@
  %7D%0A%0A
-    public List%3CString%3E getColumnList() %7B%0A        return columnList;%0A    %7D%0A%0A
     

Remove unused projection fields in data retrieval DTO