package rasel.lunar.launcher.workers

import android.annotation.SuppressLint
import android.content.Context
import androidx.work.WorkerParameters
import rasel.lunar.launcher.model.RssData
import rasel.lunar.launcher.model.getRssData
import rasel.lunar.launcher.home.adapters.RssFeedsParser
import rasel.lunar.launcher.utils.RssList.feedJsons

class RedditGetter : BaseGetter {
    constructor(context: Context, workerParams: WorkerParameters) : super(context, workerParams) {

    }

    @SuppressLint("RestrictedApi")
    override fun realWork(): Result {
        val temp = arrayListOf<RssData>()
        for (url in feedJsons) {
            for (it in RssFeedsParser.getReddit(url)) {
                if (it.pubDate() >= limitDateTime) {
                    temp.add(it.getRssData())
                }
            }
        }
        return  Result.success().apply {
            WorkersDb.insertBulkData(temp)
        }
    }
}