package com.quansu.heifengwuliu.activity

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import com.luck.picture.lib.PictureSelector
import com.quansu.heifengwuliu.R
import com.quansu.heifengwuliu.base.MBActivity
import com.quansu.heifengwuliu.config.MIntentAction
import com.quansu.heifengwuliu.databinding.ActivityComVerifyBinding
import com.quansu.heifengwuliu.inte.OnUploadCallback
import com.quansu.heifengwuliu.repository.ComVerifyRepository
import com.quansu.heifengwuliu.utils.OssUtils
import com.quansu.heifengwuliu.vmodel.ComVerityVModel
import com.ysnows.base.base.BRepository
import java.util.ArrayList

class ComVerityActivity : MBActivity<ComVerityVModel, ActivityComVerifyBinding>() , OnUploadCallback<String> {


    override fun initCreate(savedInstanceState: Bundle?) {
        super.initCreate(savedInstanceState)
        vm.getInfo()
    }

    override fun title(): String? {
        return getString(R.string.com_verify)
    }

    override fun binding(): ActivityComVerifyBinding {
        return ActivityComVerifyBinding.inflate(layoutInflater)
    }

    override fun vmClass(): Class<ComVerityVModel> {
        return ComVerityVModel::class.java
    }

    override fun createRepository(): BRepository {
        return ComVerifyRepository()
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode != Activity.RESULT_OK) {
            return
        }
        if (requestCode == MIntentAction.REQUEST_CODE_THREE) {//图片

            val selectList = PictureSelector.obtainMultipleResult(data)
            val list = ArrayList<String>()
            if (null != selectList) {
                for (path in selectList) {
                    list.add(path.path)
                }

                OssUtils(this)
                        .setUpLoad("company", list, this)

            }

            return

        }
        if (requestCode == MIntentAction.REQUEST_CODE_CAMERA) {//拍照
            //拍照
            val selectList = PictureSelector.obtainMultipleResult(data) ?: return
            val list = ArrayList<String>()
            list.add(selectList[0].path)
            OssUtils(this)
                    .setUpLoad("idcard", list, this)

            return
        }

    }

    override fun onUploadSuccess(t: String) {
        val ss: Array<String> = t.split(",".toRegex()).toTypedArray()
        vm.imgBL.value = ss[1]
    }

    override fun onUploadError(error: String?) {

    }
}
