package cn.learningpad.oraltrainer.sdk

import android.net.Uri

data class ImitationAssessmentRequest @JvmOverloads constructor(
    val mediaId: String,
    val sentence: SentenceBoundary,
    val recordingUri: Uri,
    val referenceAudioUri: Uri? = null,
    val locale: String? = null,
    val metadata: Map<String, String> = emptyMap(),
)

data class ImitationAssessmentResult @JvmOverloads constructor(
    val overallScore: Float,
    val pronunciationScore: Float? = null,
    val fluencyScore: Float? = null,
    val completenessScore: Float? = null,
    val feedback: String? = null,
    val details: Map<String, String> = emptyMap(),
    val passed: Boolean? = null,
    val contentScore: Float? = null,
    val durationScore: Float? = null,
    val pauseScore: Float? = null,
    val speechRateScore: Float? = null,
    val durationRatio: Float? = null,
    val referenceText: String? = null,
    val recognizedText: String? = null,
    val missingTokens: List<String> = emptyList(),
    val extraTokens: List<String> = emptyList(),
    val substitutions: List<Pair<String, String>> = emptyList(),
)

fun interface CancellableAssessment {
    fun cancel()
}

interface ImitationAssessmentCallback {
    fun onResult(result: ImitationAssessmentResult)

    fun onError(error: Throwable)
}

interface ImitationQualityAssessor {
    fun assess(
        request: ImitationAssessmentRequest,
        callback: ImitationAssessmentCallback,
    ): CancellableAssessment
}

object NoopImitationQualityAssessor : ImitationQualityAssessor {
    override fun assess(
        request: ImitationAssessmentRequest,
        callback: ImitationAssessmentCallback,
    ): CancellableAssessment {
        callback.onError(UnsupportedOperationException("No imitation quality assessor is configured."))
        return CancellableAssessment {}
    }
}
