package com.p3.bewoplaner.data.prefs;

import com.p3.bewoplaner.BewoplanerApplication;
import com.p3.bewoplaner.R;
import com.p3.bewoplaner.data.AppPrefsConstants;
import com.p3.bewoplaner.di.scopes.ApplicationScope;
import com.securepreferences.SecurePreferences;

import android.content.Context;
import android.content.SharedPreferences;

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.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.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);
    }

}