package com.crm.pay.controller.pay;

import com.crm.pay.controller.base.BasePayController;
import com.crm.pay.entity.telegraphic.TelegraphicAddEntity;
import com.crm.pay.service.TelegraphicPayService;
import com.crm.rely.backend.core.constant.RequestSinglePointLimiter;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.model.constant.PayConstants;
import com.crm.rely.backend.model.entity.custom.info.CustomInfoEntity;
import com.crm.rely.backend.model.entity.finance.deposit.FinanceDepositAddEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/telegraphic")
public class TelegraphicPayController extends BasePayController {

    @Autowired
    private TelegraphicPayService service;


    /**
     * 支付
     *
     * @return 错误信息
     * @throws Exception
     */
    @RequestMapping("/pay")
    @RequestSinglePointLimiter
    public BaseResultDto pay(@RequestBody @Validated TelegraphicAddEntity entity, CustomInfoEntity infoEntity) throws Exception {

        FinanceDepositAddEntity balanceSaveEntity = getFinanceDepositSaveEntity(
                entity.getLogin(),
                entity.getAmount(),
                PayConstants.UNION_PAY_TELEGRAPHIC,
                entity.getVoucherUrl(),
                infoEntity);
        service.pay(balanceSaveEntity);
        return BaseResultDto.success();
    }

}
