package cn.muchinfo.rma.business.exposure

import cn.muchinfo.rma.global.data.*
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 ExposureManager {

    /**
     * 查询实时敞口
     * @param params Map<String, String>  参数 AreaUserId
     * @param responseBack Function3<[@kotlin.ParameterName] Boolean, [@kotlin.ParameterName] List<ContractData>?, [@kotlin.ParameterName] Error?, Unit>
     */
    fun queryRealtimeExposure(
        params: Map<String, String>,
        responseBack: (isSuccess: Boolean, respData: List<RealExposureData>?, error: Error?) -> Unit
    ) {
        MyOkHttpUtils().query(
            URL = SPUtils.getInstance().getString(Constant.goCommonSearchUrl) + "/Ermcp/QueryRealtimeExposure",
            params = params,
            type = "1",
            callback = object : ResponseCallback<BaseResult<List<RealExposureData>>>(){
                override fun onResponse(response: BaseResult<List<RealExposureData>>?, 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> 参数 areaUserId
     * @param responseBack Function3<[@kotlin.ParameterName] Boolean, [@kotlin.ParameterName] List<NumberSpotData>?, [@kotlin.ParameterName] Error?, Unit>
     */
    fun queryExposureSpot(
        params: Map<String, String>,
        responseBack: (isSuccess: Boolean, respData: List<NumberSpotData>?, error: Error?) -> Unit
    ){
        MyOkHttpUtils().query(
            URL = SPUtils.getInstance().getString(Constant.goCommonSearchUrl) + "/Ermcp/QueryExposureSpot",
            params = params,
            type = "1",
            callback = object : ResponseCallback<BaseResult<List<NumberSpotData>>>(){
                override fun onResponse(response: BaseResult<List<NumberSpotData>>?, 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> 参数 areaUserId
     * @param responseBack Function3<[@kotlin.ParameterName] Boolean, [@kotlin.ParameterName] List<NumberSpotData>?, [@kotlin.ParameterName] Error?, Unit>
     */
    fun queryExposureHedgePosition(
        params: Map<String, String>,
        responseBack: (isSuccess: Boolean, respData: List<NumberSpotData>?, error: Error?) -> Unit
    ){
        MyOkHttpUtils().query(
            URL = SPUtils.getInstance().getString(Constant.goCommonSearchUrl) + "/Ermcp/QueryExposureHedgePosition",
            params = params,
            type = "1",
            callback = object : ResponseCallback<BaseResult<List<NumberSpotData>>>(){
                override fun onResponse(response: BaseResult<List<NumberSpotData>>?, 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> 参数 areaUserId : 所属机构ID lastNum : 每个品种记录数
     * @param responseBack Function3<[@kotlin.ParameterName] Boolean, [@kotlin.ParameterName] List<ExposureHistoryData>?, [@kotlin.ParameterName] Error?, Unit>
     */
    fun queryHisExposure(
        params: Map<String, String>,
        responseBack: (isSuccess: Boolean, respData: List<ExposureHistoryData>?, error: Error?) -> Unit
    ){
        MyOkHttpUtils().query(
            URL = SPUtils.getInstance().getString(Constant.goCommonSearchUrl) + "/Ermcp/QueryHisExposure",
            params = params,
            type = "1",
            callback = object : ResponseCallback<BaseResult<List<ExposureHistoryData>>>(){
                override fun onResponse(response: BaseResult<List<ExposureHistoryData>>?, 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> areaUserId ： 所属机构ID  /  middleGoodsId ：套保商品
     * @param responseBack Function3<[@kotlin.ParameterName] Boolean, [@kotlin.ParameterName] List<ExposureRealTimeDetailsData>?, [@kotlin.ParameterName] Error?, Unit>
     */
    fun queryExposureDetail(
        params: Map<String, String>,
        responseBack: (isSuccess: Boolean, respData: List<ExposureRealTimeDetailsData>?, error: Error?) -> Unit
    ){
        MyOkHttpUtils().query(
            URL = SPUtils.getInstance().getString(Constant.goCommonSearchUrl) + "/Ermcp/QueryExposureDetail",
            params = params,
            type = "1",
            callback = object : ResponseCallback<BaseResult<List<ExposureRealTimeDetailsData>>>(){
                override fun onResponse(response: BaseResult<List<ExposureRealTimeDetailsData>>?, 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> areaUserId ： 所属机构ID  /  middleGoodsId ：套保商品
     * @param responseBack Function3<[@kotlin.ParameterName] Boolean, [@kotlin.ParameterName] List<ExposureRealTimeDetailsData>?, [@kotlin.ParameterName] Error?, Unit>
     */
    fun queryRealtimeExposurePosition(
        params: Map<String, String>,
        responseBack: (isSuccess: Boolean, respData: List<ExposureRealTimeDetailsData>?, error: Error?) -> Unit
    ){
        MyOkHttpUtils().query(
            URL = SPUtils.getInstance().getString(Constant.goCommonSearchUrl) + "/Ermcp/QueryRealtimeExposurePosition",
            params = params,
            type = "1",
            callback = object : ResponseCallback<BaseResult<List<ExposureRealTimeDetailsData>>>(){
                override fun onResponse(response: BaseResult<List<ExposureRealTimeDetailsData>>?, 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] List<NumberSpotData>?, [@kotlin.ParameterName] Error?, Unit>
     */
    fun queryExposureSpotDetail(
        params: Map<String, String>,
        responseBack: (isSuccess: Boolean, respData: List<NumberSpotDetailsData>?, error: Error?) -> Unit
    ){
        MyOkHttpUtils().query(
            URL = SPUtils.getInstance().getString(Constant.goCommonSearchUrl) + "/Ermcp/QueryExposureSpotDetail",
            params = params,
            type = "1",
            callback = object : ResponseCallback<BaseResult<List<NumberSpotDetailsData>>>(){
                override fun onResponse(response: BaseResult<List<NumberSpotDetailsData>>?, 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] List<NumberSpotData>?, [@kotlin.ParameterName] Error?, Unit>
     */
    fun queryExposureHedgePositionDetail(
        params: Map<String, String>,
        responseBack: (isSuccess: Boolean, respData: List<NumberSpotDetailsData>?, error: Error?) -> Unit
    ){
        MyOkHttpUtils().query(
            URL = SPUtils.getInstance().getString(Constant.goCommonSearchUrl) + "/Ermcp/QueryExposureHedgePositionDetail",
            params = params,
            type = "1",
            callback = object : ResponseCallback<BaseResult<List<NumberSpotDetailsData>>>(){
                override fun onResponse(response: BaseResult<List<NumberSpotDetailsData>>?, id: Int) {
                    responseBack(true,response?.data,null)
                }

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

}