package com.brilliance.isc.common.bop.controller;

import com.brilliance.isc.common.util.BopUtils;
import com.brilliance.isc.common.bopset.service.RmbbopService;
import com.brilliance.isc.common.context.BopContext;
import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.rmbbop.vo.Rmbbop;
import com.brilliance.isc.common.rmbbop.vo.RmbbopRequest;
import com.brilliance.isc.common.rmbbop.vo.RmbbopResponse;
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;
import org.springframework.stereotype.Component;

@Api("跨境人民币申报服务")
@Component
public class AbstractRmbController<T1 extends BizInfoVo, T2 extends BizAmdInfoVo> {

    @Autowired
    private RmbbopService rmbbopService;

    /**
     * 跨境人民币试算
     *
     * @param rmbbopRequest RmbbopRequestVo
     * @return ResponseSet
     */
    @ApiOperation("跨境人民币试算")
    public ResponseSet<RmbbopResponse> calcRmbbop(RmbbopRequest<T1, T2> rmbbopRequest) {
        ResponseSet<RmbbopResponse> responseSet;
        try {
            BopUtils.loadSettleSession(rmbbopRequest);
            BopContext.load(rmbbopRequest);
            Rmbbop rmbbop = rmbbopRequest.getRmbbop();
            rmbbopService.calcRmbbop(rmbbop);
            RmbbopResponse rmbbopResponse = RmbbopResponse.builder().rmbbop(rmbbop).build();
            responseSet = new ResponseSet<>(rmbbopResponse);
        } finally {
            SettleContext.removeUserSession();
            BopContext.remove();
        }
        return responseSet;
    }

}
