package com.zxbw.modulemain.presenter

import android.app.Activity
import android.text.TextUtils
import android.util.Log
import com.zxbw.modulemain.contract.RightsPayContract
import com.zxbw.modulemain.contract.TbGoodsDetailContract
import com.zxhl.cms.AppContext
import com.zxhl.cms.net.ApiClient
import com.zxhl.cms.net.RxSchedulers
import com.zxhl.cms.net.SettingPreference
import com.zxhl.cms.net.callback.BaseObserver
import com.zxhl.cms.net.model.box.AppInEntity
import com.zxhl.cms.net.model.box.BoxInfoEntity
import com.zxhl.cms.net.model.box.VerifacationEntity
import com.zxhl.cms.net.model.qy.ConvertLinkEntity
import com.zxhl.cms.net.model.qy.TbGoodsEntity
import com.zxhl.cms.net.model.uc.AliPayEntity
import com.zxhl.cms.net.model.uc.PayMinEntity
import com.zxhl.cms.net.model.uc.PayVerifyEntity
import com.zxhl.cms.net.model.uc.WeChatPayEntity
import com.zxhl.cms.net.model.video.MemberEntity
import com.zxhl.cms.pay.alipay.AlipayServer
import com.zxhl.cms.utils.EventUtils
import com.zxhl.cms.utils.JumpUtils
import com.zxhl.cms.utils.UserDataUtils
import com.zxhl.cms.utils.WeChatPay
import org.json.JSONObject
import kotlin.random.Random

/**
 *商品详情
 */
class TbGoodsDetailPresenter : TbGoodsDetailContract.Presenter {

    private val mView: TbGoodsDetailContract.View

    constructor(mView: TbGoodsDetailContract.View) {
        this.mView = mView
    }

    override fun getConvertLink(link: String) {
        ApiClient.homeApi.getGoodsConvertLink(link)
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<ConvertLinkEntity>() {
                override fun onSuccess(result: ConvertLinkEntity?) {
                    mView.setConvertLink(result)
                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
                    mView.setConvertLink(null)
                }
            })
    }

    override fun getGoodsDetail(productId: String) {
        ApiClient.homeApi.getGoodsImgDetail(productId)
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<TbGoodsEntity>() {
                override fun onSuccess(result: TbGoodsEntity?) {

                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {

                }
            })
    }

    override fun getTjGoodsList() {
        var randomPage = Random.nextInt(16)
        ApiClient.homeApi.getGoodsGuessLike(randomPage, 20)
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<TbGoodsEntity>() {
                override fun onSuccess(result: TbGoodsEntity?) {
                    if (result != null) {
                        mView.setTjGoodsList(true, result.data)
                    } else {
                        mView.setTjGoodsList(true, null)
                    }
                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
                    mView.setTjGoodsList(true, null)
                }
            })
    }

}