/*
 * Copyright 2018 Google LLC
 *
 * 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 com.google.android.gnd;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.work.WorkManager;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gnd.persistence.remote.RemoteDataStore;
import com.google.android.gnd.persistence.remote.RemoteStorageManager;
import com.google.android.gnd.persistence.remote.firestore.FirestoreDataStore;
import com.google.android.gnd.persistence.remote.firestore.FirestoreStorageManager;
import com.google.android.gnd.persistence.remote.firestore.FirestoreUuidGenerator;
import com.google.android.gnd.persistence.uuid.OfflineUuidGenerator;
import com.google.android.gnd.ui.common.ViewModelModule;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.FirebaseFirestoreSettings;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import dagger.hilt.InstallIn;
import dagger.hilt.android.components.ApplicationComponent;
import javax.inject.Singleton;

@InstallIn(ApplicationComponent.class)
@Module(includes = {ViewModelModule.class})
abstract class GndApplicationModule {

  /** Provides the Firestore implementation of remote data store. */
  @Binds
  @Singleton
  abstract RemoteDataStore remoteDataStore(FirestoreDataStore ds);

  /** Provides the Firestore implementation of offline unique id generation. */
  @Binds
  @Singleton
  abstract OfflineUuidGenerator offlineUuidGenerator(FirestoreUuidGenerator uuidGenerator);

  @Provides
  @Singleton
  static GoogleApiAvailability googleApiAvailability() {
    return GoogleApiAvailability.getInstance();
  }

  @Provides
  @Singleton
  static WorkManager workManager() {
    return WorkManager.getInstance();
  }

  @Provides
  @Singleton
  static SharedPreferences sharedPreferences(Application application) {
    return application
        .getApplicationContext()
        .getSharedPreferences(Config.SHARED_PREFS_NAME, Config.SHARED_PREFS_MODE);
  }

  @Provides
  static FirebaseFirestoreSettings firebaseFirestoreSettings() {
    return new FirebaseFirestoreSettings.Builder()
        .setPersistenceEnabled(Config.FIRESTORE_PERSISTENCE_ENABLED)
        .build();
  }

  @Provides
  @Singleton
  static FirebaseFirestore firebaseFirestore(FirebaseFirestoreSettings settings) {
    FirebaseFirestore firestore = FirebaseFirestore.getInstance();
    firestore.setFirestoreSettings(settings);
    FirebaseFirestore.setLoggingEnabled(Config.FIRESTORE_LOGGING_ENABLED);
    return firestore;
  }

  /** Provides the Firestore implementation of remote storage manager. */
  @Binds
  @Singleton
  abstract RemoteStorageManager remoteStorageManager(FirestoreStorageManager fsm);

  /** Returns a reference to the default Storage bucket. */
  @Provides
  @Singleton
  static StorageReference firebaseStorageReference() {
    return FirebaseStorage.getInstance().getReference();
  }
}

@@ -658,40 +658,8 @@
 on;%0A
-import android.content.Context;%0A
 impo
@@ -692,24 +692,24 @@
 references;%0A
+
 import andro
@@ -1839,362 +1839,8 @@
  %7B%0A%0A
-  /** Provides the Firestore implementation of remote data store. */%0A  @Binds%0A  @Singleton%0A  abstract RemoteDataStore remoteDataStore(FirestoreDataStore ds);%0A%0A  /** Provides the Firestore implementation of offline unique id generation. */%0A  @Binds%0A  @Singleton%0A  abstract OfflineUuidGenerator offlineUuidGenerator(FirestoreUuidGenerator uuidGenerator);%0A%0A
   @P
@@ -2863,188 +2863,8 @@
  %7D%0A%0A
-  /** Provides the Firestore implementation of remote storage manager. */%0A  @Binds%0A  @Singleton%0A  abstract RemoteStorageManager remoteStorageManager(FirestoreStorageManager fsm);%0A%0A
   /*
@@ -3056,14 +3056,548 @@
 ence();%0A
-
   %7D
+%0A%0A  /** Provides the Firestore implementation of remote data store. */%0A  @Binds%0A  @Singleton%0A  abstract RemoteDataStore remoteDataStore(FirestoreDataStore ds);%0A%0A  /** Provides the Firestore implementation of offline unique id generation. */%0A  @Binds%0A  @Singleton%0A  abstract OfflineUuidGenerator offlineUuidGenerator(FirestoreUuidGenerator uuidGenerator);%0A%0A  /** Provides the Firestore implementation of remote storage manager. */%0A  @Binds%0A  @Singleton%0A  abstract RemoteStorageManager remoteStorageManager(FirestoreStorageManager fsm);
 %0A%7D%0A

Remove unused import