package com.tomhempel.rbarometer.data

import android.content.Context
import com.tomhempel.rbarometer.session.SessionProgramHelper

object PendingUploadRepository {

    suspend fun countUploadReady(context: Context): Int =
        getUploadReadyQuestionnaires(context).size +
            getUploadReadyScoringReviews(context).size

    suspend fun hasUploadReady(context: Context): Boolean = countUploadReady(context) > 0

    suspend fun getUploadReadyQuestionnaires(context: Context): List<CompletedQuestionnaire> =
        SessionProgramHelper.filterUploadReadyQuestionnaires(
            context,
            CompletedQuestionnaireRepository.getAllPendingUploads(),
        )

    suspend fun getUploadReadyScoringReviews(context: Context): List<CoachScoringReview> =
        SessionProgramHelper.filterUploadReadyScoringReviews(
            context,
            CoachScoringReviewRepository.getAllPendingUploads(),
        )

    /** Raw pending count (ignores session completion). */
    suspend fun countAll(): Int =
        CompletedQuestionnaireRepository.countPendingUploads() +
            CoachScoringReviewRepository.countPendingUploads()

    suspend fun hasAny(): Boolean = countAll() > 0
}
