/*------------------------------------------------------------------------------
 **    Author: René de Groot
 ** Copyright: (c) 2017 René de Groot All Rights Reserved.
 **------------------------------------------------------------------------------
 ** No part of this file may be reproduced
 ** or transmitted in any form or by any
 ** means, electronic or mechanical, for the
 ** purpose, without the express written
 ** permission of the copyright holder.
 *------------------------------------------------------------------------------
 *
 *   This file is part of "Stay-awake on adb".
 *
 *   "Stay-awake on adb" is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   "Stay-awake on adb" is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with "Stay-awake on adb".  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package nl.renedegroot.android.adbawake.businessmodel

import android.content.Context
import nl.renedegroot.android.adbawake.Application
import nl.renedegroot.android.adbawake.providers.SharedPreferencesProvider
import javax.inject.Inject

class Preferences {
    private val SERVICE_FIELD = "ServiceEnabled"

    @Inject
    lateinit var sharedPreferencesProvider: SharedPreferencesProvider

    init {
        Application.appComponent.inject(this)
    }

    fun enableService(context: Context, enabled: Boolean) {
        val prefs = sharedPreferencesProvider.getSharedPreferences(context)
        prefs.edit().putBoolean(SERVICE_FIELD, enabled).apply()
    }

    fun isServiceEnabled(context: Context): Boolean {
        return sharedPreferencesProvider.getSharedPreferences(context).getBoolean(SERVICE_FIELD, true)
    }
}
