package cn.muchinfo.rma.business.initialize

import cn.muchinfo.rma.global.data.AccountData
import cn.muchinfo.rma.global.data.UserAccountData
import cn.muchinfo.rma.global.data.database.ErrorCodeEntity
import cn.muchinfo.rma.netManage.base.ResponseCallback
import cn.muchinfo.rma.netManage.utils.MyOkHttpUtils
import cn.muchinfo.rma.view.base.app.BaseResult
import cn.muchinfo.rma.view.base.app.Constant
import com.blankj.utilcode.util.SPUtils
import okhttp3.Call
import java.lang.Exception

/**
 * 登陆后初始化数据的管理类
 */
class InitializeManager {


    /**
     * 查询资金账户信息
     * @param params Map<String, String> 参数 loginID   taAccountType（可不填） 账号类型 - 1:外部账号 2:内部账号 3:内部做市自营账号 4:内部做市接单账号
     * @param responseBack Function3<[@kotlin.ParameterName] Boolean, [@kotlin.ParameterName] List<AccountData>?, [@kotlin.ParameterName] Error?, Unit>
     */
    fun getTaAccounts(
        params: Map<String, String>,
        responseBack: (isSuccess: Boolean, respData: List<AccountData>?, error: Error?) -> Unit
    ) {
        MyOkHttpUtils().query(
            URL = SPUtils.getInstance()
                .getString(Constant.goCommonSearchUrl) + "/TaAccount/GetTaAccounts",
            params = params,
            type = "1",
            callback = object : ResponseCallback<BaseResult<List<AccountData>>>() {
                override fun onResponse(response: BaseResult<List<AccountData>>?, id: Int) {
                    responseBack(true, response?.data, null)
                }

                override fun onError(call: Call?, e: Exception?, id: Int) {
                    responseBack(false, null, Error(e?.message))
                }
            }
        )
    }


    /**
     * 获取错误信息的增量查询
     * @param params Map<String, String> rowNumber 起始行号前索引
     * @param responseBack Function3<[@kotlin.ParameterName] Boolean, [@kotlin.ParameterName] List<ErrorCodeEntity>?, [@kotlin.ParameterName] Error?, Unit>
     */
    fun queryErrorInfos(
        params: Map<String, String>,
        responseBack: (isSuccess: Boolean, respData: List<ErrorCodeEntity>?, error: Error?) -> Unit
    ) {
        MyOkHttpUtils().query(
            URL = SPUtils.getInstance()
                .getString(Constant.goCommonSearchUrl) + "/Common/QueryErrorInfos",
            params = params,
            type = "1",
            callback = object : ResponseCallback<BaseResult<List<ErrorCodeEntity>>>(){
                override fun onResponse(response: BaseResult<List<ErrorCodeEntity>>?, id: Int) {
                    responseBack(true, response?.data, null)
                }

                override fun onError(call: Call?, e: Exception?, id: Int) {
                    responseBack(false, null, Error(e?.message))
                }
            }
        )
    }

    /**
     * 获取用户账号信息
     * @param params Map<String, String>
     * @param responseBack Function3<[@kotlin.ParameterName] Boolean, [@kotlin.ParameterName] UserAccountData?, [@kotlin.ParameterName] Error?, Unit>
     */
    fun getUserAccount(
        params: Map<String, String>,
        responseBack: (isSuccess: Boolean, respData: UserAccountData?, error: Error?) -> Unit
    ){
        MyOkHttpUtils().query(
            URL = SPUtils.getInstance().getString(Constant.goCommonSearchUrl) + "/User/GetUserAccount",
            params = params,
            type = "1",
            callback = object : ResponseCallback<BaseResult<UserAccountData>>(){
                override fun onResponse(response: BaseResult<UserAccountData>, id: Int) {
                    responseBack(true, response.data, null)
                }

                override fun onError(call: Call?, e: Exception?, id: Int) {
                    responseBack(false, null, Error(e?.message))
                }
            }
        )
    }


}