package com.github.nullptroma.wallenc.domain.errors

/**
 * Единая иерархия сбоев Wallenc. Ожидаемые бизнес-отказы (CanEncryptResult и т.п.)
 * остаются отдельными sealed-типами; сюда попадают только операционные ошибки.
 */
sealed class WallencException(
    message: String? = null,
    cause: Throwable? = null,
) : Exception(message, cause) {

    sealed class Feature : WallencException() {
        class StorageNotFound : Feature()
        class NeedsDecryptedView : Feature()
        class SecretNotFound : Feature()
        class StorageNotWritable : Feature()
    }

    sealed class Storage(cause: Throwable? = null) : WallencException(cause = cause) {
        class NotAvailable : Storage()
        class FileNotFound : Storage()
        class IncorrectKey : Storage()
        class EncInfoMissing : Storage()
        class NotEncrypted : Storage()
        class NotWritable : Storage()
        class NotAFile : Storage()
        class NotADirectory : Storage()
        class PathIsFile : Storage()
        class CannotWriteOverDirectory : Storage()
        class DeleteRootForbidden : Storage()
        class UnexpectedState : Storage()
        data class IoFailed(override val cause: Throwable) : Storage(cause)
    }

    sealed class Auth : WallencException() {
        class Failed : Auth()
        class TokenMissing : Auth()
    }

    sealed class Network(cause: Throwable? = null) : WallencException(cause = cause) {
        data class HttpFailed(
            val operation: String,
            val statusCode: Int,
            override val cause: Throwable? = null,
        ) : Network(cause)

        data class IoFailed(override val cause: Throwable) : Network(cause)
        class ResourceLocked : Network()
        class OperationFailed : Network()
        class OperationTimedOut : Network()
    }

    data class Unknown(override val cause: Throwable?) : WallencException(cause = cause)
}
