package com.remax.visualnovel.ui.wallet

/**
 * Created by HJW on 2025/8/26
 */

import com.remax.visualnovel.app.viewmodel.base.BaseViewModel
import com.remax.visualnovel.entity.request.ChargeProduct
import com.remax.visualnovel.entity.request.PageQuery
import com.remax.visualnovel.entity.request.SearchPage
import com.remax.visualnovel.entity.response.Transaction
import com.remax.visualnovel.entity.response.base.Response
import com.remax.visualnovel.repository.api.PayRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class WalletViewModel @Inject constructor(private val payRepository: PayRepository) : BaseViewModel() {

    private var currPn = 1

    suspend fun getBillList(isRefresh: Boolean, type: String?): Response<Transaction> {
        if (isRefresh) currPn = 1
        return payRepository.getTransactionList(
            SearchPage(
                PageQuery.Page(currPn), type = type
            )
        ).transformResult({
            currPn++
        })
    }


    suspend fun getMyWallet() = payRepository.getMyWallet()

    var products: List<ChargeProduct>? = null
        private set

    suspend fun getProducts() = payRepository.getProducts().transformResult({
        products = it?.productList
        products?.firstOrNull()?.selected = true
    })

}
