package eu.gaudian.translator.utils

import android.content.Context
import eu.gaudian.translator.model.Language
import eu.gaudian.translator.model.communication.ApiManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext


class CorrectionService(context: Context) {

    private val apiRequestHandler = ApiRequestHandler(
        ApiManager(context),
        context = context
    )

    suspend fun correctText(
        textToCorrect: String,
        language: Language,
        grammarOnly: Boolean,
        tone: String?
    ): Result<CorrectionResponse> = withContext(Dispatchers.IO) {

        @Suppress("HardCodedStringLiteral")
        Log.d("correctText", "$textToCorrect, ${language.englishName}, tone:$tone")

        val template = TextCorrectionRequest(
            textToCorrect = textToCorrect,
            language = language.englishName,
            grammarOnly = grammarOnly,
            tone = tone
        )

        apiRequestHandler.executeRequest(template)
    }
}