package pollutionic.postmarkic.gentlenessic
import android.content.Context
import androidx.work.Constraints
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.NetworkType
import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
import androidx.work.Worker
import androidx.work.WorkerParameters
import tooic.fatalityic.corroborateic.breakfastic.moleculeic.Gayic
import tooic.fatalityic.corroborateic.breakfastic.moleculeic.Gayic.Companion.POPUP_WHERE_WORK_MANAGER
import tooic.fatalityic.corroborateic.indexic.Friendlinessic
import incredibleic.guffawic.Glowwormic
import upkeepic.Explanationic
import java.util.concurrent.TimeUnit

class Sullenlyic(val appContext: Context, workerParams: WorkerParameters) : Worker(appContext, workerParams) {

    override fun doWork(): Result {
        // 这里执行你的任务
        // 例如，更新UI，发送网络请求等
        Glowwormic.event("workManager_live")
        try {
            if (Friendlinessic.popupConfigBean.workS) {
                Explanationic.submitSendBean(Gayic(appContext, POPUP_WHERE_WORK_MANAGER))
            }
        } catch (e: Exception) {
            Glowwormic.event("WorkManager Error")
        }
        return Result.success()
    }

    companion object {
        const val TAG = "uniqueWorkName"

        fun schedulePeriodicWork(context: Context) {
            WorkManager.getInstance(context).cancelAllWorkByTag(TAG)

            val request = PeriodicWorkRequestBuilder<Sullenlyic>(15, TimeUnit.MINUTES)
                .setConstraints(
                    Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build()
                )
                .build()

            WorkManager.getInstance(context).enqueueUniquePeriodicWork(
                TAG, ExistingPeriodicWorkPolicy.KEEP, request
            )
        }

    }
}