package com.mall.order.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.common.domain.vo.result.PageResult;
import com.mall.common.domain.vo.result.Result;
import com.mall.common.domain.vo.result.ResultCodeEnum;
import com.mall.order.domain.dto.OrderReturnApplyDto;
import com.mall.order.domain.entity.OrderReturnApply;
import com.mall.order.domain.vo.OrderReturnApplyVo;
import com.mall.order.service.OrderReturnApplyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单退货申请 前端控制器
 * </p>
 *
 * @author Bunny
 * @since 2025-07-05 18:54:06
 */
@Tag(name = "订单退货申请", description = "订单退货申请相关接口")
@RestController
@RequestMapping("/api/order/order-return-apply")
@RequiredArgsConstructor
public class OrderReturnApplyController {

    private final OrderReturnApplyService orderReturnApplyService;

    @Operation(summary = "分页查询订单退货申请", description = "分页订单退货申请")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<OrderReturnApplyVo>> getOrderReturnApplyPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            OrderReturnApplyDto dto) {
        Page<OrderReturnApply> pageParams = new Page<>(page, limit);
        PageResult<OrderReturnApplyVo> pageResult = orderReturnApplyService.getOrderReturnApplyPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加订单退货申请", description = "添加订单退货申请")
    @PostMapping()
    public Result<String> addOrderReturnApply(@Valid @RequestBody OrderReturnApplyDto dto) {
        orderReturnApplyService.addOrderReturnApply(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新订单退货申请", description = "更新订单退货申请")
    @PutMapping()
    public Result<String> updateOrderReturnApply(@Valid @RequestBody OrderReturnApplyDto dto) {
        orderReturnApplyService.updateOrderReturnApply(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除订单退货申请", description = "删除订单退货申请")
    @DeleteMapping()
    public Result<String> deleteOrderReturnApply(@RequestBody List<Long> ids) {
        orderReturnApplyService.deleteOrderReturnApply(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}