package com.remax.visualnovel.ui.chat.message.detail.flirting

/**
 * Created by HJW on 2025/8/16
 */
import com.remax.visualnovel.app.viewmodel.base.BaseViewModel
import com.remax.visualnovel.entity.request.AIIsShowDTO
import com.remax.visualnovel.entity.request.HeartbeatBuy
import com.remax.visualnovel.entity.response.HeartbeatLevelOutput
import com.remax.visualnovel.repository.api.ChatRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class FlirtingLevelViewModel @Inject constructor(private val chatRepository: ChatRepository) : BaseViewModel() {

    var levelOutput: HeartbeatLevelOutput? = null
        private set

    suspend fun getHeartbeatLevel(aiId: String) = chatRepository.getHeartbeatLevel(aiId).transformResult({
        levelOutput = it
    })

    suspend fun relationSwitch(request: AIIsShowDTO) = chatRepository.relationSwitch(request).transformResult({
        levelOutput?.aiUserHeartbeatRelation?.isShow = request.isShow == 1
    })

    suspend fun buyHeartbeatVal(aiId: String) = chatRepository.buyHeartbeatVal(HeartbeatBuy(
        aiId,
        levelOutput?.aiUserHeartbeatRelation?.subtractHeartbeatVal
    ))
}
