/*
 * Copyright 2017 Google Inc.
 *
 * 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
 *
 *    https://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.dataportabilityproject.shared;

import com.google.common.collect.ImmutableList;
import org.dataportabilityproject.cloud.interfaces.JobDataCache;
import org.dataportabilityproject.dataModels.DataModel;
import org.dataportabilityproject.dataModels.Exporter;
import org.dataportabilityproject.dataModels.Importer;

import java.io.IOException;

import org.dataportabilityproject.shared.auth.AuthData;
import org.dataportabilityproject.shared.auth.OfflineAuthDataGenerator;
import org.dataportabilityproject.shared.auth.OnlineAuthDataGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A service provider that supports importing and export different data types.
 */
public interface ServiceProvider {
    Logger logger = LoggerFactory.getLogger(ServiceProvider.class);

    String getName();

    ImmutableList<PortableDataType> getExportTypes();

    ImmutableList<PortableDataType> getImportTypes();

    /**
     * Return an OfflineAuthDataGenerator for the provided dataType. The returned generator will
     * have permissions based on the serviceMode provided.
     */
    default OfflineAuthDataGenerator getOfflineAuthDataGenerator(PortableDataType dataType, ServiceMode serviceMode) {
      // default implementation to ignore serviceMode
      return getOfflineAuthDataGenerator(dataType);
    }

    /**
     * Same as above but retrieves AuthGenerator for read/write access (ignoring serviceMode).
     * TODO: remove once all serviceProviders implement the above version of this method.
     */
    @Deprecated
    default OfflineAuthDataGenerator getOfflineAuthDataGenerator(PortableDataType dataType){
      logger.debug("WARNING: getOnlineAuthDataGenerator not implemented for type: {}, service: {}",
          dataType, getName());
      return null;
    };

    /* Return an OnlineAuthDataGenerator for the provided  dataType. The returned generator will have permissions based
     * on the serviceMode provided.
     */
    default OnlineAuthDataGenerator getOnlineAuthDataGenerator(PortableDataType dataType, ServiceMode serviceMode) {
        // default implementation is to ignore serviceMode
        return getOnlineAuthDataGenerator(dataType);
    }

    /* Same as above, but retrieves AuthGenerator for read/write access (ignoring serviceMode)
     * TODO: remove once all serviceProviders implement the above version of this method.
     */
    @Deprecated
    default OnlineAuthDataGenerator getOnlineAuthDataGenerator(PortableDataType dataType) {
        logger.debug("WARNING: getOnlineAuthDataGenerator not implemented for type: {}, service: {}",
                dataType, getName());
        return null;
    }

    Exporter<? extends DataModel> getExporter(
            PortableDataType type,
            AuthData authData,
            JobDataCache jobDataCache) throws IOException;

    Importer<? extends DataModel> getImporter(
            PortableDataType type,
            AuthData authData,
            JobDataCache jobDataCache) throws IOException;
}
@@ -680,16 +680,44 @@
 leList;%0A
+import java.io.IOException;%0A
 import o
@@ -943,38 +943,8 @@
 er;%0A
-%0Aimport java.io.IOException;%0A%0A
 impo
@@ -1821,75 +1821,37 @@
     
-// default implementation to ignore serviceMode%0A      return 
+logger.warn(%0A          %22
 getO
-ff
+n
 line
@@ -1871,392 +1871,8 @@
 ator
-(dataType);%0A    %7D%0A%0A    /**%0A     * Same as above but retrieves AuthGenerator for read/write access (ignoring serviceMode).%0A     * TODO: remove once all serviceProviders implement the above version of this method.%0A     */%0A    @Deprecated%0A    default OfflineAuthDataGenerator getOfflineAuthDataGenerator(PortableDataType dataType)%7B%0A      logger.debug(%22WARNING: getOnlineAuthDataGenerator
  not
@@ -1883,32 +1883,49 @@
 lemented for typ
+e: %7B%7D, serviceMod
 e: %7B%7D, service: 
@@ -1940,32 +1940,45 @@
        dataType,
+ serviceMode,
  getName());%0A   
@@ -1998,17 +1998,17 @@
 l;%0A    %7D
-;
+%0A
 %0A%0A    /*
@@ -2097,16 +2097,23 @@
 tor will
+%0A     *
  have pe
@@ -2127,23 +2127,16 @@
 ns based
-%0A     *
  on the 
@@ -2292,60 +2292,20 @@
     
-  // default implementation is to ignore serviceMode
+logger.warn(
 %0A   
@@ -2309,23 +2309,19 @@
         
-return 
+  %22
 getOnlin
@@ -2342,385 +2342,8 @@
 ator
-(dataType);%0A    %7D%0A%0A    /* Same as above, but retrieves AuthGenerator for read/write access (ignoring serviceMode)%0A     * TODO: remove once all serviceProviders implement the above version of this method.%0A     */%0A    @Deprecated%0A    default OnlineAuthDataGenerator getOnlineAuthDataGenerator(PortableDataType dataType) %7B%0A        logger.debug(%22WARNING: getOnlineAuthDataGenerator
  not
@@ -2354,38 +2354,54 @@
 lemented for typ
+e: %7B%7D, serviceMod
 e: %7B%7D
-,
  service: %7B%7D%22,%0A 
@@ -2405,30 +2405,24 @@
 ,%0A          
-      
 dataType, ge
@@ -2418,16 +2418,29 @@
 ataType,
+ serviceMode,
  getName
@@ -2440,26 +2440,24 @@
 getName());%0A
-  
       return

Delete deprecated versions of get*AuthDataGenerator that don't use serviceMode