package rasel.lunar.launcher.workers

import android.content.Context
import androidx.annotation.CallSuper
import androidx.work.Worker
import androidx.work.WorkerParameters
import rasel.lunar.launcher.model.RssData
import rasel.lunar.launcher.utils.beforeDay
import java.util.Calendar
import java.util.Date

open abstract class BaseGetter : Worker {
    protected companion object {
        var lastedUpdateTime = 0L
        val defaultDay = 3
        fun before10Min(): Long {
            val cal: Calendar = Calendar.getInstance()
            cal.setTime(Date())
            cal.add(Calendar.MINUTE, -10)
            return cal.timeInMillis
        }
    }
    val USAGT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/605.1.15"
    val now = Date()
    val limitDateTime = beforeDay(now,3)
    val commicsDateTime = beforeDay(now,1)
    val temp = arrayListOf<RssData>()

    constructor(context: Context, workerParams: WorkerParameters) : super(context, workerParams) {
    }

    @CallSuper
    override fun doWork(): Result {
        val currentTime = before10Min()
        if (lastedUpdateTime > 0L && currentTime  > lastedUpdateTime) {
            return Result.success().apply {

            }
        }
        return realWork().apply {

        }
    }
    abstract fun realWork() : Result
}