package ru.myitschool.work.domain.profile

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

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