package com.dahe.gldriver.ui.account.authperson

import android.os.Bundle
import com.dahe.gldriver.R
import com.dahe.gldriver.bean.UpQualiInfoBean
import com.dahe.gldriver.databinding.ActivityAuthQualificationBinding
import com.dahe.gldriver.net.BaseObserver
import com.dahe.gldriver.net.DataManager
import com.dahe.gldriver.net.RxHttpCallBack
import com.dahe.gldriver.oss.OssServiceUtil
import com.dahe.mylibrary.utils.PickerUtils
import com.dahe.mylibrary.base.BaseActivity
import com.dahe.mylibrary.net.CommonResponseBean
import com.dahe.mylibrary.utils.ActivityUtils
import com.dahe.mylibrary.utils.ImageLoader
import com.dahe.mylibrary.utils.PopsUtils
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.schedulers.Schedulers

/**
 * @ClassName AuthQualificationActivity
 * @Author john
 * @Date 2024/1/25 15:20
 * @Description 从业资格证认证
 */
class AuthQualificationActivity : BaseActivity<ActivityAuthQualificationBinding>() {

    var ossServiceUtil: OssServiceUtil = OssServiceUtil.getInstance()
    var upQuaInfo = UpQualiInfoBean()
    override fun initView(savedInstanceState: Bundle?) {
        setStatusBarColor(R.color.white)
        setTitleBar("实名认证", true)
        binding.btnOk.setOnClickListener {
            subMit()
        }

        binding.run {
            tvDate.run {
                setOnClickListener {
                    PickerUtils.getInstance()
                        .showDateSim(
                            this@AuthQualificationActivity,
                            "选择有效期至"
                        ) { date ->
                            this.text = date
                        }
                }
            }

            ivFront.setOnClickListener {
                PopsUtils.getInstance().showSimSelPic(mContext) {
                    var data = it[0]
                    ossServiceUtil.asyncPutImage(data.realPath, this@AuthQualificationActivity)
                    ossServiceUtil.setResultCallBack { data, oldPath ->
                        upQuaInfo.qualificationCertificatePhotoUrl = oldPath
                        runOnUiThread {
                            ImageLoader.getInstance()
                                .loadRoundImage(mContext, it[0].realPath, 12, ivFront)
                        }

                    }

                }
            }
        }
    }

    override fun initDate() {
    }

    private fun subMit() {
        upQuaInfo.run {
            qualificationCertificateNo = binding.etId.text.toString()
            qualificationCertificateEffectiveEnd = binding.tvDate.text.toString()

            DataManager.getInstance().setUpDriverQualificationCertificate(upQuaInfo)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(BaseObserver(mContext, object : RxHttpCallBack<String>() {
                    override fun onSuccess(t: CommonResponseBean<String>) {
                        super.onSuccess(t)
                        ActivityUtils.startActivity(mContext, AuthBankCardActivity::class.java)
                    }
                }))
        }
    }
}