package de.beyondsoft.ownchat.data.prefs;

import de.beyondsoft.ownchat.BewoplanerApplication;
import de.beyondsoft.ownchat.R;
import de.beyondsoft.ownchat.data.AppPrefsConstants;
import de.beyondsoft.ownchat.di.scopes.ApplicationScope;
import com.securepreferences.SecurePreferences;

import android.content.Context;
import android.content.SharedPreferences;
import android.provider.Settings;

import javax.inject.Named;

import dagger.Module;
import dagger.Provides;

/**
 * Created by imarneanu on 2/10/17.
 */
@Module
public class AppPrefsModule {
    @Provides
    @ApplicationScope
    @AppPrefs
    SharedPreferences provideSharedPreferences(BewoplanerApplication app) {
        return app.getSharedPreferences(app.getString(R.string.app_name), Context.MODE_PRIVATE);
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.API_ENDPOINT)
    StringPreference provideApiEndpoint(@AppPrefs SharedPreferences sharedPreferences) {
        return new StringPreference(sharedPreferences, AppPrefsConstants.API_ENDPOINT);
    }

    @Provides
    @ApplicationScope
    @AppPrefs
    SecurePreferences provideSecuredPrefs(BewoplanerApplication application) {
        return new SecurePreferences(application, "", "my_prefs_1000.xml");
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.LOGIN_TOKEN)
    StringPreference provideLoginToken(@AppPrefs SharedPreferences sharedPreferences) {
        return new StringPreference(sharedPreferences, AppPrefsConstants.LOGIN_TOKEN);
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.SAVE_PASSWORD)
    BooleanPreference provideSavePassword(@AppPrefs SecurePreferences sharedPreferences) {
        return new BooleanPreference(sharedPreferences, AppPrefsConstants.SAVE_PASSWORD);
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.IS_COMING_FROM_SHARING_ACTIVITY)
    BooleanPreference provideIsComingFromSharingActivity(@AppPrefs SecurePreferences sharedPreferences) {
        return new BooleanPreference(sharedPreferences, AppPrefsConstants.IS_COMING_FROM_SHARING_ACTIVITY);
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.IS_FILE)
    BooleanPreference provideIsFile(@AppPrefs SecurePreferences sharedPreferences) {
        return new BooleanPreference(sharedPreferences, AppPrefsConstants.IS_FILE);
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.PATH_TO_FILE_TO_SHARE)
    StringPreference providePathToFileToShare(@AppPrefs SecurePreferences sharedPreferences) {
        return new StringPreference(sharedPreferences, AppPrefsConstants.PATH_TO_FILE_TO_SHARE);
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.VERIFY_CHAT_CODE_ERROR_MESSAGE)
    StringPreference provideVerifyChatCodeErrorMessage(@AppPrefs SecurePreferences sharedPreferences) {
        return new StringPreference(sharedPreferences, AppPrefsConstants.VERIFY_CHAT_CODE_ERROR_MESSAGE);
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.USER_NAME)
    StringPreference provideUserName(@AppPrefs SecurePreferences sharedPreferences) {
        return new StringPreference(sharedPreferences, AppPrefsConstants.USER_NAME);
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.USER_PASSWORD)
    StringPreference providePassword(@AppPrefs SecurePreferences sharedPreferences) {
        return new StringPreference(sharedPreferences, AppPrefsConstants.USER_PASSWORD);
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.CHAT_CODE)
    StringPreference provideChatCode(@AppPrefs SecurePreferences sharedPreferences) {
        return new StringPreference(sharedPreferences, AppPrefsConstants.CHAT_CODE);
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.ACCOUNT_NO)
    StringPreference provideAccountNumber(@AppPrefs SecurePreferences sharedPreferences) {
        return new StringPreference(sharedPreferences, AppPrefsConstants.ACCOUNT_NO);
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.LAST_ACCOUNT_NO)
    StringPreference provideLastAccountNumber(@AppPrefs SecurePreferences sharedPreferences) {
        return new StringPreference(sharedPreferences, AppPrefsConstants.LAST_ACCOUNT_NO);
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.USER_ID)
    LongPreference provideUserId(@AppPrefs SharedPreferences sharedPreferences) {
        return new LongPreference(sharedPreferences, AppPrefsConstants.USER_ID);
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.AVATAR)
    StringPreference provideAvatar(@AppPrefs SharedPreferences sharedPreferences) {
        return new StringPreference(sharedPreferences, AppPrefsConstants.AVATAR);
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.NAME)
    StringPreference provideProfileName(@AppPrefs SharedPreferences sharedPreferences) {
        return new StringPreference(sharedPreferences, AppPrefsConstants.NAME);
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.PHONE_NUMBER)
    StringPreference providePhoneNumber(@AppPrefs SharedPreferences sharedPreferences) {
        return new StringPreference(sharedPreferences, AppPrefsConstants.PHONE_NUMBER);
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.CHAT_OPENED)
    BooleanPreference provideChatOpened(@AppPrefs SharedPreferences sharedPreferences) {
        return new BooleanPreference(sharedPreferences, AppPrefsConstants.CHAT_OPENED);
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.APP_KILLED)
    BooleanPreference provideAppKilled(@AppPrefs SharedPreferences sharedPreferences) {
        return new BooleanPreference(sharedPreferences, AppPrefsConstants.APP_KILLED);
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.UPLOAD_MAX_SIZE)
    LongPreference provideUploadMaxSize(@AppPrefs SharedPreferences sharedPreferences) {
        return new LongPreference(sharedPreferences, AppPrefsConstants.UPLOAD_MAX_SIZE);
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.IS_EMPLOYEE)
    BooleanPreference provideIsEmployee(@AppPrefs SharedPreferences sharedPreferences) {
        return new BooleanPreference(sharedPreferences, AppPrefsConstants.IS_EMPLOYEE);
    }

    @Provides
    @ApplicationScope
    @Named(AppPrefsConstants.SHOW_LOGIN_AGAIN)
    BooleanPreference provideShowLoginAgain(@AppPrefs SharedPreferences sharedPreferences) {
        return new BooleanPreference(sharedPreferences, AppPrefsConstants.SHOW_LOGIN_AGAIN);
    }
}