package com.ruoyi.web.controller.info;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.info.order.domain.bo.OrderRefundBo;
import com.ruoyi.info.order.domain.vo.OrderRefundVo;
import com.ruoyi.info.order.enums.OrderOperatorType;
import com.ruoyi.info.order.service.IOrderRefundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 售后订单Controller
 *
 * @author ruoyi
 * @date 2025-09-29
 */
@Validated
@Api(value = "售后订单控制器", tags = {"售后订单管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/order/orderRefund")
public class OrderRefundController extends BaseController {

    private final IOrderRefundService iOrderRefundService;

    /**
     * 分页查询售后订单列表
     */
    @ApiOperation("查询售后订单列表")
    @SaCheckPermission("order:orderRefund:list")
    @GetMapping("/page")
    public TableDataInfo<OrderRefundVo> page(@Validated(QueryGroup.class) OrderRefundBo bo, PageQuery pageQuery) {
        return iOrderRefundService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取售后订单详细信息
     */
    @ApiOperation("获取售后订单详细信息")
    @SaCheckPermission("order:orderRefund:query")
    @GetMapping("/info/{id}")
    public R<OrderRefundVo> getInfo(@ApiParam("主键")
                                                  @NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return R.ok(iOrderRefundService.queryById(id));
    }

    /**
     * 同意或拒绝售后订单
     */
    @ApiOperation("同意或拒绝售后订单")
    @SaCheckPermission("order:orderRefund:agreeOrRefuse")
    @Log(title = "售后订单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/agreeOrRefuse")
    public R<Void> agreeOrRefuse(@RequestBody OrderRefundBo bo) {
        bo.setOperatorId(getUserId());
        bo.setOperatorType(OrderOperatorType.platform.getCode());
        return toAjax(iOrderRefundService.agreeOrRefuse(bo) ? 1 : 0);
    }

}
