package com.github.nullptroma.wallenc.domain.tasks

import com.github.nullptroma.wallenc.domain.errors.WallencException

interface TaskContext {
    val taskId: TaskId

    suspend fun reportProgress(fraction: Float?, label: TaskProgressLabel? = null)

    suspend fun reportProgress(progress: TaskProgress) = reportProgress(progress.fraction, progress.label)

    fun log(level: TaskLogLevel, message: String)

    fun log(level: TaskLogLevel, key: TaskLogKey)

    fun fail(error: WallencException): Nothing

    /** Проверяет, что задача не отменена; бросает [kotlinx.coroutines.CancellationException] при отмене. */
    suspend fun ensureNotCancelled()
}
