package ru.myitschool.work.data.source

import dagger.Reusable
import retrofit2.Retrofit
import ru.myitschool.work.data.dto.OpenQrDto
import ru.myitschool.work.data.dto.UserInfoDto
import javax.inject.Inject

@Reusable
class AccountNetworkDataSource @Inject constructor(
    private val retrofit: Retrofit
) {
    private val api by lazy {
        retrofit.create(AccountApi::class.java)
    }

    suspend fun getInfo(username: String): Result<UserInfoDto> {
        return kotlin.runCatching { api.getInfo(username = username) }
    }

    suspend fun openByQr(username: String, content: String): Result<Unit> {
        return kotlin.runCatching {
            api.openByQr(
                username = username,
                content = OpenQrDto(value = content)
            )
        }
    }
}