package com.gamedog.vididin.beans

import com.ama.core.architecture.util.AndroidUtil
import com.ama.core.architecture.util.DateUtil
import com.gamedog.vididin.manager.WithdrawManager
import com.gamedog.vididin.manager.WithdrawManager.Companion.TRANSACTION_STATE_FAIL
import com.gamedog.vididin.manager.WithdrawManager.Companion.TRANSACTION_STATE_ONGOING
import com.gamedog.vididin.manager.WithdrawManager.Companion.TRANSACTION_STATE_SUCCESS
import com.viddin.videos.free.R


// Record 类型
const val RECORD_CASH_PLUS_GOLD_CONVERT: Int = 1
const val RECORD_CASH_PLUS_BOX_TASK: Int = 2
const val RECORD_CASH_PLUS_WITHDRAW_ONGOING: Int = 3
const val RECORD_CASH_WITHDRAW: Int = 4
const val RECORD_CASH_ZERO_WITHDRAW_SUCCESS: Int = 5

abstract class BaseRecord {
    var dateMs: Long = DateUtil.getCurTimeMs()
    var uuid: String = AndroidUtil.randomUUid()
}

open class RecordCash (var recordType: Int = 0,
                       var amountNum: Double = 0.0,) : BaseRecord() {

    // 提现相关的
    var payInitItemId: Int = 0
    var payOutReplyId: String = ""
    var payOutReplyNo: String = ""
    var withdrawState: Int = TRANSACTION_STATE_ONGOING    // 提现状态 1:提现中,2:提现成功,3:提现失败
    var withdrawFailType: Int = WithdrawManager.INIT_OK
    var withdrawItemIndex: Int = -1
    var withdrawItemLoopIndex: Int = -1
    var withdrawItemSubIndex: Int = -1
    var withdrawInitUUID: String = ""
    var hasShowResultDialog: Boolean = false

}

class RecordCashShow: RecordCash() {
    var title: Int = 0
    var description: Int = 0
    var iconRes: Int = 0
    var textColor: Int = R.color.green_39
}


fun RecordCash.toShowBean(): RecordCashShow {
    return RecordCashShow().apply {
        this@apply.uuid = this@toShowBean.uuid
        this@apply.dateMs = this@toShowBean.dateMs
        this@apply.amountNum = this@toShowBean.amountNum
        this@apply.recordType = this@toShowBean.recordType
        this@apply.withdrawState = this@toShowBean.withdrawState
        this@apply.withdrawFailType = this@toShowBean.withdrawFailType

        when (this@apply.recordType) {
            RECORD_CASH_PLUS_GOLD_CONVERT -> {
                title = R.string.record_cash_title_convert_from_gold
                description = R.string.record_cash_descr_convert_from_gold
                iconRes = R.mipmap.task_gold
                textColor = R.color.green_39
            }

            RECORD_CASH_PLUS_BOX_TASK -> {
                title = R.string.record_cash_title_box
                description = R.string.record_cash_descr_box
                iconRes = R.mipmap.icon_gift
                textColor = R.color.green_39
            }

            RECORD_CASH_PLUS_WITHDRAW_ONGOING -> {
                title = R.string.record_cash_title_withdraw_ongoing
                description = R.string.record_cash_descr_withdraw_onging
                iconRes = R.mipmap.icon_convert_cash
                textColor = R.color.red_28
            }

            RECORD_CASH_WITHDRAW -> {
                this@apply.amountNum = -this@toShowBean.amountNum
                when (withdrawState) {
                    TRANSACTION_STATE_ONGOING -> {
                        title = R.string.record_cash_title_withdraw_ongoing
                        description = R.string.record_cash_descr_withdraw_onging
                        iconRes = R.mipmap.icon_withdraw_ongoing
                        textColor = R.color.green_39
                    }

                    TRANSACTION_STATE_SUCCESS -> {
                        title = R.string.record_cash_title_withdraw_success
                        description = R.string.record_cash_descr_withdraw_success
                        iconRes = R.mipmap.icon_check
                        textColor = R.color.green_39
                    }

                    TRANSACTION_STATE_FAIL -> {
                        title = R.string.record_cash_title_withdraw_failed
                        description = WithdrawManager.instance().getFailHintStrRes(withdrawFailType)
                        iconRes = R.mipmap.icon_fail
                        textColor = R.color.gray3
                    }
                }
            }

            RECORD_CASH_ZERO_WITHDRAW_SUCCESS -> {
                title = R.string.record_cash_title_zero
                description = R.string.record_cash_descr_zero
                iconRes = R.mipmap.icon_zero
                textColor = R.color.green_39
            }
        }
    }
}