package com.example.lexilearn.data.repository

import com.example.lexilearn.data.model.AnswerType
import com.example.lexilearn.data.model.MaterialDataModel
import com.example.lexilearn.data.model.QuestionType
import com.example.lexilearn.data.model.QuizAnswer
import com.example.lexilearn.data.model.QuizQuestion
import kotlin.random.Random


class QuizRepository {

fun generateQuestion(
    material: MaterialDataModel,
    questionMode: Int,
    answerMode: Int
): QuizQuestion {
    val questionType = when (questionMode) {
//        1 -> listOf(QuestionType.TEXT, QuestionType.IMAGE).random()
        1 -> QuestionType.TEXT
        2 -> QuestionType.AUDIO
        else -> QuestionType.TEXT
    }

    val question = when (questionType) {
//        QuestionType.TEXT -> listOf(material.idName, material.idDescription).random()
        QuestionType.TEXT -> material.idName
        QuestionType.IMAGE -> material.image
        QuestionType.AUDIO -> material.enName
    } ?: "Soal tidak tersedia"

    val answerType = when (answerMode) {
        1 -> AnswerType.FULL_WORD
        2 -> AnswerType.SHUFFLED_LETTERS
        else -> AnswerType.FULL_WORD
    }

    return QuizQuestion(
        questionType = questionType,
        question = question,
        urlImage = material.image,
        correctAnswer = QuizAnswer(
            answerType = answerType,
            correctWord = material.enName
        )
    )
}

    fun getRandomMaterials(
        nData: Int,
        materials: List<MaterialDataModel>,
        callback: (List<MaterialDataModel>) -> Unit
    ) {
        if (materials.isNotEmpty()) {
            val randomMaterials = materials.shuffled().take(nData)
            callback(randomMaterials)
        } else {
            callback(emptyList())
        }
    }

}