package com.ruoyi.api.controller.info;

import com.ruoyi.api.controller.common.AbstractApiController;
import com.ruoyi.common.annotation.RepeatSubmit;
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.AddGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.info.order.domain.bo.OrderRefundBo;
import com.ruoyi.info.order.domain.vo.OrderRefundVo;
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("/api/orderRefund")
public class ApiOrderRefundController extends AbstractApiController {

    private final IOrderRefundService iOrderRefundService;

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

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

    /**
     * 新增售后订单
     */
    @ApiOperation("新增售后订单")
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OrderRefundBo bo) {
        bo.setUserId(getUserId());
        return toAjax(iOrderRefundService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 取消售后订单
     */
    @ApiOperation("取消售后订单")
    @RepeatSubmit()
    @PostMapping("/cancel/{id}")
    public R<Void> cancel(@ApiParam("主键")
                          @NotNull(message = "主键不能为空")
                          @PathVariable("id") Long id) {
        return toAjax(iOrderRefundService.cancel(id) ? 1 : 0);
    }

}
