package com.all.pdfreader.pro.app.sp

import android.content.Context
import com.all.pdfreader.pro.app.model.SortConfig
import com.all.pdfreader.pro.app.sp.store.Store
import com.all.pdfreader.pro.app.sp.store.asStoreProvider

class AppStore(context: Context) {
    private val store = Store(
        context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE).asStoreProvider()
    )

    //权限提示的对话框是否已经展示过
    var isShowPermissionsDialogPrompt: Boolean by store.boolean(
        key = PERMISSIONS_DIALOG_PROMPT, defaultValue = false
    )

    // 文档排序配置
    var documentSortType: String by store.string(
        key = DOCUMENT_SORT_TYPE, defaultValue = SortConfig.default().toPreferenceString()
    )

    var favoriteSortType: String by store.string(
        key = DOCUMENT_FAVORITE_SORT_TYPE, defaultValue = SortConfig.default().toPreferenceString()
    )

    // 是否开启护眼遮罩
    var isEyeCareMode: Boolean by store.boolean(
        key = IS_EYE_CARE_MODE, defaultValue = false
    )

    // 横or竖
    var isVertical: Boolean by store.boolean(
        key = IS_VERTICAL, defaultValue = true//默认竖
    )

    // 是否逐页
    var isPageFling: Boolean by store.boolean(
        key = IS_PAGE_FLING, defaultValue = false
    )

    // 是否反转颜色
    var isColorInversion: Boolean by store.boolean(
        key = IS_COLOR_INVERSION, defaultValue = false
    )

    var keepScreenOn: Boolean by store.boolean(
        key = KEEP_SCREEN_ON,defaultValue = false
    )

    companion object {
        private const val FILE_NAME = "prp_sp_name"
        private const val PERMISSIONS_DIALOG_PROMPT = "permissions_dialog_prompt"
        private const val DOCUMENT_SORT_TYPE = "document_sort_type"
        private const val DOCUMENT_FAVORITE_SORT_TYPE = "document_favorite_sort_type"
        private const val IS_EYE_CARE_MODE = "is_eye_care_mode"
        private const val IS_VERTICAL = "is_vertical"
        private const val IS_PAGE_FLING = "is_page_fling"
        private const val IS_COLOR_INVERSION = "is_color_inversion"
        private const val KEEP_SCREEN_ON = "keep_screen_on"
    }
}