package com.github.libretube.api

object PanelAuthHelper {
    suspend fun realizarLogin(username: String, password: String): Result<LoginResponse> {
        return try {
            val response = PanelRetrofitInstance.apiService.login(
                LoginRequest(
                    username = username,
                    password = password
                )
            )
            Result.success(response)
        } catch (exception: Exception) {
            Result.failure(exception)
        }
    }

    suspend fun validarToken(token: String): Result<TokenValidationResponse> {
        return try {
            val response = PanelRetrofitInstance.apiService.validateToken(
                TokenValidationRequest(token = token)
            )
            Result.success(response)
        } catch (exception: Exception) {
            Result.failure(exception)
        }
    }

    suspend fun enviarLatidoReproduccion(code: String): Result<PlaybackHeartbeatResponse> {
        return try {
            Result.success(PanelRetrofitInstance.apiService.checkPlaybackCode(code))
        } catch (exception: Exception) {
            // A transient network/server error must never interrupt playback.
            Result.failure(exception)
        }
    }
}
