package com.ai.da.controller;

import com.ai.da.common.response.Response;
import com.ai.da.model.dto.ProductPurchaseDTO;
import com.ai.da.service.AlipayHKService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;

@CrossOrigin
@RestController
@RequestMapping("/api/alipay-hk")
@Tag(name = "网站支付 香港支付宝")
@Slf4j
public class AlipayHKController {

    @Resource
    private AlipayHKService alipayHKService;

    @Operation(summary = "创建订单")
    @PostMapping(value = "/createOrder")
    public Response<String> createOrder(@Valid @RequestBody ProductPurchaseDTO productPurchaseDTO, HttpServletRequest request) {
        String order = alipayHKService.createOrder(productPurchaseDTO, request);
        return Response.success(order);
    }

    @Operation(summary = "支付通知")
    @PostMapping("/trade/notify")
    public String callback(@RequestBody String paramString){
        log.info("alipay-hk callback parameter : {}", paramString);
        return alipayHKService.callback(paramString);
    }

    @Operation(summary = "订单查询")
    @PostMapping("/trade/query/{orderRef}")
    public Response<String> queryOrder(@PathVariable String orderRef){
        String s = alipayHKService.queryDetail(orderRef);
        return Response.success(s);
    }



}
