package com.muchinfo.mtp3century.controller;

import com.muchinfo.mtp3century.service.IBankAccountSignService;
import com.muchinfo.mtp3century.utils.CenturyDecryptUtil;
import com.muchinfo.mtp3common.enumtype.Constants;
import com.muchinfo.mtp3common.enumtype.MessageType;
import com.muchinfo.mtp3century.utils.AjaxResult;
import com.muchinfo.mtp3common.utils.JsonUtils;
import com.muchinfo.mtp3common.vo.PageResult;
import com.muchinfo.mtp3pojos.entity.BankCusbankinfo;
import com.muchinfo.mtp3pojos.vo.bankaccountsign.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

@RestController
@RequestMapping("/accountSign")
@Api(value = "资金账户API", description = "资金账户管理")
public class BankAccountController {
    private final Logger log = LoggerFactory.getLogger(this.getClass());
    @Resource
    private IBankAccountSignService iBankAccountSignService;

    @ApiOperation("资金账户管理->银行签约信息/签解约管理列表")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/query")
    public PageResult<AccountSignQueryResult> query(AccountSignQueryParam taAccountQueryParam, HttpServletRequest request) {
        return iBankAccountSignService.query(taAccountQueryParam, request);
    }

    @ApiOperation("资金账户管理->银行签约-->初始化托管银行")
    @RequestMapping(method = RequestMethod.GET, value = "/dealAccountSignInit")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult<BankCusbankinfo> dealAccountSignInit(Long accountid ,HttpServletRequest request) {
        return iBankAccountSignService.dealAccountSignInit(accountid,request);
    }

    @ApiOperation("资金账户管理-->处理银行签约")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.POST, value = "/dealAccountSign")
    public AjaxResult dealAccountSign(@RequestBody String param, HttpServletRequest request) {
        try {
            AccountSignParam insertParam = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(param, request), AccountSignParam.class);
            return iBankAccountSignService.dealAccountSign(request, insertParam);
        } catch (Exception e) {
            log.error("银行签约新增签约失败，失败原因：" + Arrays.toString(e.getStackTrace()));
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }

    @ApiOperation("获取签约银行详细信息")
    @RequestMapping(method = RequestMethod.GET, value = "/getSignBankById")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult<BankAccountsignResult> getSignBankById(String accountcode, String cusbankid, String applyexchticket, HttpServletRequest request) {
        return iBankAccountSignService.getSignBankById(accountcode, cusbankid, applyexchticket, request);
    }

    @ApiOperation("银行业务/查询管理-->出入金查询")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/queryPutOrIn")
    public PageResult<PutOrInAmountQueryResult> queryPutOrIn(PutOrInAmountQueryParam param, HttpServletRequest request) {
        return iBankAccountSignService.queryPutOrIn(param, request);
    }

    @ApiOperation("银行业务/查询管理-->出入金查询详情")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/queryPutOrInDetail")
    public AjaxResult<PutOrInAmountQueryResultDetail> queryPutOrInDetail(String accountcode, String cusbankid, String tradedate, String exchticket, HttpServletRequest request) {
        return iBankAccountSignService.queryPutOrInDetail(accountcode, cusbankid, tradedate, exchticket, request);
    }
}
