package shop.alien.store.controller;

import com.alipay.api.AlipayApiException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiSort;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.dto.AlipayTradeSettleConfirmDto;
import shop.alien.store.service.AlipaySettleService;

/**
 * 支付宝结算接口 — alipay.trade.settle.confirm 等。
 */
@Slf4j
@Api(tags = {"支付宝-结算"})
@ApiSort(20)
@CrossOrigin
@RestController
@RequestMapping("/store/alipay/settle")
@RequiredArgsConstructor
public class AlipaySettleController {

    private final AlipaySettleService alipaySettleService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "确认结算", notes = "alipay.trade.settle.confirm；直付通/分账场景在支付成功后调用")
    @PostMapping("/confirm")
    public R<String> tradeSettleConfirm(@RequestBody AlipayTradeSettleConfirmDto request) throws AlipayApiException {
        log.info("AlipaySettleController.tradeSettleConfirm outRequestNo={}, tradeNo={}",
                request != null ? request.getOutRequestNo() : null,
                request != null ? request.getTradeNo() : null);
        return alipaySettleService.tradeSettleConfirm(request);
    }
}
