package com.czg.controller.admin;

import com.czg.annotation.SaAdminCheckPermission;
import com.czg.log.annotation.OperationLog;
import com.czg.order.dto.CommonRefundDTO;
import com.czg.order.dto.GbOrderQueryParam;
import com.czg.order.service.GbOrderService;
import com.czg.order.vo.GbOrderDetailVO;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 拼团商品
 *
 * @author ww
 */
@RestController
@RequestMapping("/admin/gbOrder")
public class GbOrderController {

    @Resource
    private GbOrderService orderService;

    /**
     * 拼团商品:订单列表
     */
    @GetMapping("page")
    @SaAdminCheckPermission(parentName = "拼团商品", value = "ware:order:list", name = "拼团商品-订单列表")
    public CzgResult<Page<GbOrderDetailVO>> getGbOrderPage(GbOrderQueryParam param) {
        if (param.getShopId() == null) {
            param.setShopId(StpKit.USER.getShopId());
        }
        Page<GbOrderDetailVO> page = orderService.getGbOrderPage(param);
        return CzgResult.success(page);
    }

    /**
     * 拼团商品:核销
     *
     * @param verifyCode 核销码
     */
    @PostMapping("checkout")
    @OperationLog("拼团商品-核销")
    @SaAdminCheckPermission(parentName = "拼团商品", value = "ware:order:checkout", name = "拼团商品-核销")
    public CzgResult<Boolean> checkout(@RequestBody String verifyCode) {
        return CzgResult.success(orderService.checkout(verifyCode, StpKit.USER.getShopId()));
    }

    /**
     * 退单/同意退单
     */
    @PostMapping("/agreeRefund")
    public CzgResult<Boolean> agreeRefund(@RequestBody @Validated CommonRefundDTO param) {
        return CzgResult.success(orderService.agreeRefund(param, StpKit.USER.getShopId()));
    }

    /**
     * 驳回退单
     */
    @PostMapping("/rejectRefund")
    public CzgResult<Boolean> rejectRefund(@RequestBody @Validated CommonRefundDTO param) {
        return CzgResult.success(orderService.cancelRefund(param, null, StpKit.USER.getShopId()));
    }

}