package com.horrortv.app.domain.model

sealed class AppError {
    abstract val userMessage: String
    abstract val debugMessage: String
    abstract val cause: Throwable?
    abstract val isRetryable: Boolean
    
    data class NetworkError(
        override val userMessage: String = "Error de conexión. Verifica tu internet.",
        override val debugMessage: String = "Network error",
        override val cause: Throwable? = null
    ) : AppError() {
        override val isRetryable: Boolean = true
    }
    
    data class ApiError(
        override val userMessage: String = "Error del servicio.",
        override val debugMessage: String = "API error",
        val code: Int = 0,
        override val cause: Throwable? = null
    ) : AppError() {
        override val isRetryable: Boolean = code in retryableCodes
    }
    
    data class CacheError(
        override val userMessage: String = "Error de datos.",
        override val debugMessage: String = "Cache error",
        override val cause: Throwable? = null
    ) : AppError() {
        override val isRetryable: Boolean = true
    }
    
    data class ValidationError(
        override val userMessage: String = "Datos inválidos.",
        override val debugMessage: String = "Validation error",
        val field: String = "",
        override val cause: Throwable? = null
    ) : AppError() {
        override val isRetryable: Boolean = false
    }
    
    data class UnknownError(
        override val userMessage: String = "Error inesperado. Intenta de nuevo.",
        override val debugMessage: String = "Unknown error",
        override val cause: Throwable? = null
    ) : AppError() {
        override val isRetryable: Boolean = cause is java.io.IOException
    }
    
    companion object {
        private val retryableCodes = setOf(429, 500, 502, 503, 504)
    }
}