package com.remax.visualnovel.repository.api

import com.remax.visualnovel.api.service.UserService
import com.remax.visualnovel.entity.request.CompleteUserInfoInput
import com.remax.visualnovel.manager.login.LoginManager
import com.remax.visualnovel.repository.api.base.BaseRepository
import com.pengxr.modular.eventbus.generated.events.EventDefineOfUserEvents
import javax.inject.Inject

/**
 * Created by HJW on 2022/10/28
 *
 * 用户相关
 */
open class UserRepository @Inject constructor(
    private val userService: UserService
) : BaseRepository() {

    suspend fun signToday() = executeHttp {
        userService.signToday()
    }

    /*suspend fun getSignList() = executeHttp {
        userService.getSignList()
    }*/

    suspend fun updateUserInfo(request: CompleteUserInfoInput) = executeHttp {
        userService.updateUserInfo(request)
    }.transformResult({
        EventDefineOfUserEvents.onUserInfoChanged().post(null)
    })

    /**
     * 获取当前登录用户的基本信息，并且更新本地信息
     */
    suspend fun getMyBaseInfo() = executeHttp {
        userService.getMyBaseInfo()
    }.transformResult({
        LoginManager.putUser(it)
    })

    suspend fun getMyCharactersList() = executeHttp {
        userService.getMyCharactersList()
    }

    suspend fun deleteAccount() = executeHttp {
        userService.deleteAccount()
    }.transformResult({
        LoginManager.logout()
     })

    /**
     * 获取当前登录用户的网易云信信息
     */
    /*suspend fun getNimInfo() = executeHttp(false) {
        userService.getNimInfo()
    }*/
}
