/*
 * 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;
}
@@ -1817,431 +1817,8 @@
 ) %7B%0A
-      // default implementation to ignore serviceMode%0A      return getOfflineAuthDataGenerator(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
     
@@ -1890,32 +1890,49 @@
 ed for type: %7B%7D,
+ serviceMode: %7B%7D,
  service: %7B%7D%22,%0A 
@@ -1941,32 +1941,45 @@
        dataType,
+ serviceMode,
  getName());%0A   
@@ -1999,17 +1999,17 @@
 l;%0A    %7D
-;
+%0A
 %0A%0A    /*
@@ -2098,16 +2098,23 @@
 tor will
+%0A     *
  have pe
@@ -2128,23 +2128,16 @@
 ns based
-%0A     *
  on the 
@@ -2287,430 +2287,8 @@
 ) %7B%0A
-        // default implementation is to ignore serviceMode%0A        return getOnlineAuthDataGenerator(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  
     
@@ -2360,32 +2360,48 @@
 ed for type: %7B%7D,
+ serviceMode: %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.