package com.fastest.pass.app

sealed class Result<out T> {
    data class Success<out T>(val data: T) : Result<T>()
    data class Failure(val exception: Throwable) : Result<Nothing>()
    data object Loading : Result<Nothing>()
}

abstract class BaseUseCase<in Params, ResultType> {

    abstract suspend fun execute(params: Params): ResultType

    suspend operator fun invoke(params: Params, onResult: (Result<ResultType>) -> Unit) {
        try {
            onResult(Result.Loading) // Notify loading state
            val result = execute(params) // Execute the actual logic (subclass implementation)
            onResult(Result.Success(result)) // Wrap the result in Result.Success
        } catch (e: Exception) {
            onResult(Result.Failure(e)) // Handle exception as failure
        }
    }
}
