package com.tomhempel.rbarometer.questionnaire

import android.content.Context
import com.tomhempel.rbarometer.network.QuestionnaireCache

object ClientAssignmentGuard {

    fun isAssigned(context: Context, clientCode: String): Boolean {
        if (clientCode.isBlank()) return false
        val assigned = QuestionnaireCache.getAssignedClients(context)
        return assigned.isNotEmpty() &&
            assigned.any { it.equals(clientCode, ignoreCase = true) }
    }

    fun canPersistAnswers(context: Context, answers: Map<String, Any>): Boolean {
        val clientCode = answers["client_code"] as? String ?: return false
        return isAssigned(context, clientCode)
    }
}
