package com.crm.manager.controller;

import com.crm.manager.service.ucard.UcardFeignService;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.dto.base.ResultWithPagerDto;
import com.crm.rely.backend.core.dto.ucard.*;
import com.crm.rely.backend.core.entity.ucard.*;
import com.crm.rely.backend.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 银行卡服务接口
 */
@Slf4j
@RestController
@RequestMapping("/ucard")
public class UcardController {

    @Autowired
    private UcardFeignService cardFeignService;

    /**
     * 获取卡片类型列表
     */
    @PostMapping("/card/types/page")
    public ResultWithPagerDto<CardTypeDto> getCardTypePageList(@RequestBody CardTypePageEntity entity) throws ServiceException {
        return cardFeignService.getCardTypePageList(entity);
    }

    /**
     * 更新卡片类型列表
     */
    @PostMapping("/card/types")
    public BaseResultDto getCardTypes() throws ServiceException {
        return cardFeignService.getCardTypes();
    }

    /**
     * 商户用户分页列表
     */
    @PostMapping("/merchant/user/page")
    public ResultWithPagerDto<MerchantUserDto> getMerchantUserPageLists(@RequestBody MerchantUserPageEntity entity) throws ServiceException {
        return cardFeignService.getMerchantUserPageList(entity);
    }

    /**
     * 查询商户账户信息
     */
    @PostMapping("/merchant/account")
    public BaseResultDto<List<MerchantAccountDto>> queryMerchantAccount() throws ServiceException {
        return cardFeignService.queryMerchantAccount();
    }

    /**
     * 商户用户注册
     */
    @PostMapping("/merchant/user/register")
    public BaseResultDto registerMerchantUser(@RequestBody MerchantUserEntity request) throws ServiceException {
        return cardFeignService.registerMerchantUser(request);
    }

    /**
     * 更新商户用户信息
     */
    @PostMapping("/merchant/user/update")
    public BaseResultDto updateMerchantUser(@RequestBody MerchantUserEntity request) throws ServiceException {
        return cardFeignService.updateMerchantUser(request);
    }

    /**
     * 获取kyc认证分页列表
     */
    @PostMapping("/merchant/kyc/page")
    ResultWithPagerDto<CardKycStatusDto> getKycPageList(@RequestBody CardKycStatusPageEntity entity) throws ServiceException{
        return cardFeignService.getKycPageList(entity);
    }

    /**
     * 上传KYC附件
     */
    @PostMapping("/merchant/kyc/upload")
    public BaseResultDto uploadKycAttachment(@RequestBody KycAttachmentUploadEntity request) throws ServiceException {
        return cardFeignService.uploadKycAttachment(request);
    }

    /**
     * 提交KYC认证
     */
    @PostMapping("/merchant/kyc/submit")
    public BaseResultDto submitKyc(@RequestBody KycEntity request) throws ServiceException {
        return cardFeignService.submitKyc(request);
    }

    /**
     * 查询KYC认证状态
     */
    @PostMapping("/merchant/kyc/status")
    public BaseResultDto<KycStatusDto> queryKycStatus(@RequestBody KycEntity entity) throws ServiceException {
        return cardFeignService.queryKycStatus(entity);
    }

    /**
     * 申请开卡
     */
    @PostMapping("/card/apply")
    public BaseResultDto applyCard(@RequestBody CardApplyEntity request) throws ServiceException {
        return cardFeignService.applyCard(request);
    }

    /**
     * 查询开卡进度
     */
    @PostMapping("/card/apply/progress")
    public BaseResultDto<CardApplyProgressDto> queryApplyProgress(@RequestBody CardApplyProgressEntity request) throws ServiceException {
        return cardFeignService.queryApplyProgress(request);
    }

    /**
     * 获取卡片申请列表
     */
    @PostMapping("/card/apply/page")
    public ResultWithPagerDto<CardApplyDto> getCardApplyPageList(@RequestBody CardApplyPageEntity entity) throws ServiceException {
        return cardFeignService.getCardApplyPageList(entity);
    }

    /**
     * 获取卡片列表
     */
    @PostMapping("/card/page")
    public ResultWithPagerDto<UcardCardDto> getCardPageList(@RequestBody CardPageEntity entity) throws ServiceException {
        return cardFeignService.getCardPageList(entity);
    }

    /**
     * 银行卡激活
     */
    @PostMapping("/card/activate")
    public BaseResultDto<CardActivateDto> activateCard(@RequestBody CardActivateEntity request) throws ServiceException {
        return cardFeignService.activateCard(request);
    }

    /**
     * 查询充值预估到账金额
     */
    @PostMapping("/card/recharge/estimate")
    public BaseResultDto<CardRechargeEstimateDto> queryRechargeEstimate(@RequestBody CardRechargeEstimateEntity request) throws ServiceException {
        return cardFeignService.queryRechargeEstimate(request);
    }

    /**
     * 银行卡充值
     */
    @PostMapping("/card/recharge")
    public BaseResultDto<CardRechargeDto> rechargeCard(@RequestBody CardRechargeEntity request) throws ServiceException {
        return cardFeignService.rechargeCard(request);
    }

    /**
     * 查询充值订单
     */
    @PostMapping("/card/recharge/order")
    public BaseResultDto<CardRechargeOrderDto> queryRechargeOrder(@RequestBody CardRechargeOrderQueryEntity request) throws ServiceException {
        return cardFeignService.queryRechargeOrder(request);
    }

    /**
     * 查询充值记录
     */
    @PostMapping("/card/recharge/records")
    public BaseResultDto<CardRechargeOrderListDto> queryRechargeRecords(@RequestBody CardRechargeRecordQueryEntity request) throws ServiceException {
        return cardFeignService.queryRechargeRecords(request);
    }

    /**
     * 充值记录分页查询
     */
    @PostMapping("/card/recharge/page")
    public ResultWithPagerDto<CardRechargeOrderDto> queryRechargePageList(@RequestBody CardRechargePageEntity request) throws ServiceException {
        return cardFeignService.queryRechargePageList(request);
    }

    /**
     * 查询卡片余额
     */
    @PostMapping("/card/balance")
    public BaseResultDto<List<CardBalanceDto>> queryCardBalance(@RequestBody CardBalanceEntity request) throws ServiceException {
        return cardFeignService.queryCardBalance(request);
    }

    /**
     * 找回密码
     */
    @PostMapping("/card/password/reset")
    public BaseResultDto resetPassword(@RequestBody CardOperateEntity request) throws ServiceException {
        return cardFeignService.resetPassword(request);
    }

    /**
     * 查询交易记录分页列表
     */
    @PostMapping("/card/transac/page")
    public ResultWithPagerDto<CardTransacOrderDto> getTransactionPageList(@RequestBody CardTransacOrderPageEntity request) throws ServiceException {
        return cardFeignService.getTransactionPageList(request);
    }

    /**
     * 查询交易记录
     */
    @PostMapping("/card/transac")
    public BaseResultDto<CardTransacOrderListDto> queryTransactions(@RequestBody CardTransacQueryEntity request) throws ServiceException {
        return cardFeignService.queryTransactions(request);
    }

    /**
     * 冻结卡片
     */
    @PostMapping("/card/freeze")
    public BaseResultDto<CardFreezeDto> freezeCard(@RequestBody CardOperateEntity request) throws ServiceException {
        return cardFeignService.freezeCard(request);
    }

    /**
     * 解冻卡片
     */
    @PostMapping("/card/unfreeze")
    public BaseResultDto<CardFreezeDto> unfreezeCard(@RequestBody CardOperateEntity request) throws ServiceException {
        return cardFeignService.unfreezeCard(request);
    }

    /**
     * 查询速汇银行及相关配置
     */
    @PostMapping("/transfer/banks")
    public BaseResultDto<List<GlobalTransferBankDto>> queryBankList() throws ServiceException {
        return cardFeignService.queryBankList();
    }

    /**
     * 查询法币汇率
     */
    @PostMapping("/transfer/rate")
    public BaseResultDto<GlobalExchangeRateDto> queryExchangeRate(@RequestBody GlobalExchangeRateEntity request) throws ServiceException {
        return cardFeignService.queryExchangeRate(request);
    }

    /**
     * 代付校验
     */
    @PostMapping("/transfer/validate")
    public BaseResultDto validateTransfer(@RequestBody GlobalPaymentEntity request) throws ServiceException {
        return cardFeignService.validateTransfer(request);
    }

    /**
     * 代付付款人校验
     */
    @PostMapping("/transfer/validate/payer")
    public BaseResultDto validatePayer(@RequestBody GlobalPayerEntity request) throws ServiceException {
        return cardFeignService.validatePayer(request);
    }

    /**
     * 代付收款人校验
     */
    @PostMapping("/transfer/validate/payee")
    public BaseResultDto validatePayee(@RequestBody GlobalPayeeEntity request) throws ServiceException {
        return cardFeignService.validatePayee(request);
    }

    /**
     * 代付
     */
    @PostMapping("/transfer")
    public BaseResultDto<GlobalPaymentDto> transfer(@RequestBody GlobalPaymentEntity request) throws ServiceException {
        return cardFeignService.transfer(request);
    }

    /**
     * 用户订单列表
     */
    @PostMapping("/transfer/orders")
    public BaseResultDto<GlobalPaymentOrderListDto> queryOrderList(@RequestBody GlobalTransferOrderEntity request) throws ServiceException {
        return cardFeignService.queryOrderList(request);
    }

    /**
     * 用户代付订单分页查询
     */
    @PostMapping("/transfer/page")
    public ResultWithPagerDto<GlobalPaymentOrderDto> queryOrderPageList(@RequestBody GlobalPaymentPageEntity request) throws ServiceException {
        return cardFeignService.queryOrderPageList(request);
    }

    /**
     * 提交调单信息或文件
     */
    @PostMapping("/transfer/dispute")
    public BaseResultDto submitDispute(@RequestBody GlobalSubmitDisputeEntity request) throws ServiceException {
        return cardFeignService.submitDispute(request);
    }

    /**
     * 查询代付订单结果
     */
    @PostMapping("/transfer/order/result")
    public BaseResultDto<GlobalOrderInfoDto> queryOrderResult(@RequestBody GlobalOrderQueryEntity request) throws ServiceException {
        return cardFeignService.queryOrderResult(request);
    }

    /**
     * 上传文件
     */
    @PostMapping("/upload/file")
    public BaseResultDto<String> uploadFile(@RequestParam(value = "file") MultipartFile file) throws ServiceException {
        return cardFeignService.uploadFile(file);
    }

    /**
     * 回调通知
     */
    @PostMapping("/callback")
    public BaseResultDto callbackNotify(@RequestBody UcardBaseRequest request) throws ServiceException {
        return cardFeignService.callbackNotify(request);
    }

    /**
     * 查询国家和城市
     */
    @PostMapping("/card/country")
    public BaseResultDto getCardCountry(@RequestBody CardCountryEntity request) throws ServiceException {
        return cardFeignService.getCardCountryList(request);
    }

    /**
     * 更新国家/城市/手机区号
     */
    @PostMapping("/card/update/country")
    public BaseResultDto cardUpdateCountry() throws ServiceException {
        return cardFeignService.cardUpdateCountry();
    }

}
