package com.brilliance.isc.common.api.lim.controller;

import com.brilliance.isc.common.api.lim.service.LimApiService;
import com.brilliance.isc.common.api.lim.vo.LimRequest;
import com.brilliance.isc.common.api.lim.vo.LimResponse;
import com.brilliance.isc.common.api.lim.vo.YapinRequest;
import com.brilliance.isc.common.api.lim.vo.YapinResponse;
import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.transaction.help.TransactionHelpService;
import com.brilliance.isc.common.vo.BizAmdInfoVo;
import com.brilliance.isc.common.vo.BizInfoVo;
import com.brilliance.isc.vo.ResponseSet;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

@Api("额度服务")
public class AbstractLimController<T1 extends BizInfoVo, T2 extends BizAmdInfoVo> {

    @Autowired
    private LimApiService limApiService;

    @Autowired
    private SettleContext settleContext;

    @Autowired
    private TransactionHelpService transactionHelpService;

    /**
     *额度查询
     * @param limRequest
     * @return ResponseSet<LiaccvResponse>
     */
    @ApiOperation("额度查询")
    public ResponseSet<LimResponse> limQuery(LimRequest<T1, T2> limRequest) {
        try {
            settleContext.loadSettleSession(limRequest.getTransName(), limRequest.getUserId(), limRequest.getRec(), limRequest.getPtsList());
            return ResponseSet.simpleSuccess(limApiService.limQuery(limRequest));
        } catch (Exception e) {
            throw e;
        } finally {
            SettleContext.removeUserSession();
        }
    }

    /**
     * 额度试算
     * @param limRequest
     * @return
     */
    @ApiOperation("额度试算")
    public ResponseSet<LimResponse> limPreCal(LimRequest<T1, T2> limRequest) {
        try {
            settleContext.loadSettleSession(limRequest.getTransName(), limRequest.getUserId(), limRequest.getRec(), limRequest.getPtsList());
            return ResponseSet.simpleSuccess(limApiService.limPreCal(limRequest));
        } catch (Exception e) {
            throw e;
        } finally {
            SettleContext.removeUserSession();
        }
    }

    @ApiOperation("额度初始化")
    public ResponseSet<LimResponse> limInit(LimRequest<T1, T2> limRequest) {
        try {
            settleContext.loadSettleSession(limRequest.getTransName(), limRequest.getUserId(), limRequest.getRec(), limRequest.getPtsList());
            return ResponseSet.simpleSuccess(limApiService.limInit(limRequest));
        } catch (Exception e) {
            throw e;
        } finally {
            SettleContext.removeUserSession();
        }
    }
    @ApiOperation("额度转授权查询")
    public ResponseSet<LimResponse> limZsqQuery(LimRequest<T1, T2> limRequest) {
        try {
            settleContext.loadSettleSession(limRequest.getTransName(), limRequest.getUserId(), limRequest.getRec(), limRequest.getPtsList());
            return ResponseSet.simpleSuccess(limApiService.limZsqQuery(limRequest));
        } catch (Exception e) {
            throw e;
        } finally {
            SettleContext.removeUserSession();
        }
    }
    @ApiOperation("押品信息试算")
    public ResponseSet<YapinResponse> yapinQuery(YapinRequest<T1, T2> yapinRequest) {
        try {
            settleContext.loadSettleSession(yapinRequest.getTransName(), yapinRequest.getUserId(), yapinRequest.getRec(), yapinRequest.getPtsList());
            return ResponseSet.simpleSuccess(limApiService.yapinInit(yapinRequest));
        } catch (Exception e) {
            throw e;
        } finally {
            SettleContext.removeUserSession();
        }
    }

}
