package com.crm.pay.controller.pay;

import com.crm.pay.controller.base.BasePayController;
import com.crm.pay.entity.digital.DigitalAddEntity;
import com.crm.pay.service.DigitalPayService;
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("/digital")
public class DigitalPayController extends BasePayController {

    @Autowired
    private DigitalPayService digitalPayService;


    @RequestMapping("/pay")
    @RequestSinglePointLimiter
    public BaseResultDto pay(@RequestBody @Validated DigitalAddEntity entity, CustomInfoEntity infoEntity) throws Exception {

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

}
