package com.dumpster.cleaner.bean

import com.dumpster.cleaner.utils.AppPreferences
import com.dumpster.cleaner.utils.KotlinExt.toFormatTime4

class FeatureBean(
    val key: String = "",
    val titleRes: Int = 0,
    val icon: Int = 0,
    val content: Int = 0,
) {
    var span: Int = 1

    companion object {
        const val JUNK_CLEAN = "junk_clean"
        const val BATTERY_INFO = "battery_info"
        const val SCREENSHOT_CLEAN = "screenshot_clean"
        const val LARGE_FILE_CLEAN = "large_file_clean"
        const val PHOTO_COMPRESSION = "photo_compression"
        const val SIMILAR_PHOTOS = "similar_photos"

        const val RECOVERY_PHOTOS = "recovery_photos"
        const val RECOVERY_VIDEOS = "recovery_videos"
        const val RECOVERY_AUDIOS = "recovery_audios"
        const val RECOVERY_DOCUMENTS = "recovery_documents"


        fun isTodayUsedFunction(): Boolean {
            val flag1 = getFunctionTodayUsed(BATTERY_INFO)
            val flag2 = listOf(
                JUNK_CLEAN,
                SCREENSHOT_CLEAN,
                LARGE_FILE_CLEAN,
                PHOTO_COMPRESSION,
                SIMILAR_PHOTOS,
                RECOVERY_PHOTOS,
                RECOVERY_VIDEOS,
                RECOVERY_AUDIOS,
                RECOVERY_DOCUMENTS
            ).filter { getFunctionTodayUsed(it) }.size >= 2
            return flag1 || flag2
        }

        /**
         * 今天功能使用过否
         */
        fun getFunctionTodayUsed(key: String): Boolean {
            return AppPreferences.getInstance().getBoolean("${key}_${System.currentTimeMillis().toFormatTime4()}", false)
        }

        /**
         * 设置今天功能使用过
         */
        fun setFunctionTodayUsed(key: String, used: Boolean = true) {
            return AppPreferences.getInstance().put("${key}_${System.currentTimeMillis().toFormatTime4()}", used)
        }


    }
}