package org.springblade.modules.app.web;

import com.wn.common.controller.BaseController;
import com.wn.common.datamodel.ResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springblade.modules.app.entity.PaymentAccount;
import org.springblade.modules.app.service.IPayService;
import org.springblade.modules.app.vo.NotifyVo;
import org.springblade.modules.app.vo.PaymentAccountVO;
import org.springblade.modules.app.vo.SignContractVo;
import org.springblade.modules.app.vo.SmartPayVo;
import org.springblade.modules.system.entity.Dict;
import org.springblade.modules.system.service.IDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("app/smart/pay")
public class SmartPayController extends BaseController {

    @Autowired
    private IPayService payService;

    @Autowired
    private IDictService dictService;

    @PostMapping("sendSms")
    public ResponseEntity<ResultDTO<String>> sendSms(@RequestBody SmartPayVo smartPayVo) {
        log.error("data is {}",smartPayVo);
        payService.sendSms(smartPayVo.getMobile(),smartPayVo.getType());
        return success();
    }

    @PostMapping("bindCollection")
    public ResponseEntity<ResultDTO<String>> bindCollection(@RequestBody SignContractVo signContractVo) {
        log.error("data is {}",signContractVo);
        payService.signAccount(signContractVo);
        return success();
    }

    @PostMapping("unbindCollection")
    public ResponseEntity<ResultDTO<String>> unbindCollection(@RequestBody SignContractVo signContractVo) {
        log.error("data is {}",signContractVo);
        payService.cancelAccount(signContractVo);
        return success();
    }

    @PostMapping("quickPayOrder")
    public ResponseEntity<ResultDTO<String>> quickPayOrder(@RequestBody SmartPayVo smartPayVo) {
        log.error("data is {}",smartPayVo);
        payService.quickPayOrder(smartPayVo);
        return success();
    }

    @PostMapping("quickPay")
    public ResponseEntity<ResultDTO<String>> quickPay(@RequestBody SmartPayVo smartPayVo) {
        log.error("data is {}",smartPayVo);
        payService.quickPay(smartPayVo);
        return success();
    }

    @GetMapping("notify")
    public String notifyGet(NotifyVo notifyVo) {
        log.error("notify get data is {}",notifyVo);
        payService.payNotify(notifyVo);
        return "success";
    }

    @PostMapping("notify")
    public String notifyPost(@RequestBody NotifyVo notifyVo) {
        log.error("notify post data is {}",notifyVo);
        payService.payNotify(notifyVo);
        return "success";
    }

    @GetMapping("bankList")
    public ResponseEntity<ResultDTO<List<Dict>>> bankList() {
        return success(dictService.getList("bank"));
    }

    @GetMapping("accountList")
    public ResponseEntity<ResultDTO<List<PaymentAccount>>> accountList(SmartPayVo smartPayVo) {
        return success(payService.accountList(smartPayVo));
    }

    @PostMapping("addAccount")
    public ResponseEntity<ResultDTO<String>> addAccount(@RequestBody PaymentAccountVO paymentAccountVO) {
        log.error("notify post data is {}",paymentAccountVO);
        payService.addPayAccount(paymentAccountVO);
        return success();
    }


}
