package ru.myitschool.work.domain.profile

import ru.myitschool.work.domain.auth.GetLoginUseCase
import ru.myitschool.work.domain.profile.repo.UserInfoRepository
import javax.inject.Inject

class OpenByQrUseCase @Inject constructor(
    private val repo: UserInfoRepository,
    private val getLoginUseCase: GetLoginUseCase,
) {
    suspend operator fun invoke(content: String): Result<Unit> {
        return getLoginUseCase().fold(
            onSuccess = { username -> repo.openByQr(username = username, content = content) },
            onFailure = { error -> Result.failure(error) }
        )
    }
}