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.OrderReturnReasonDto;
import com.mall.order.domain.entity.OrderReturnReason;
import com.mall.order.domain.vo.OrderReturnReasonVo;
import com.mall.order.service.OrderReturnReasonService;
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-reason")
@RequiredArgsConstructor
public class OrderReturnReasonController {

    private final OrderReturnReasonService orderReturnReasonService;

    @Operation(summary = "分页查询退货原因", description = "分页退货原因")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<OrderReturnReasonVo>> getOrderReturnReasonPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            OrderReturnReasonDto dto) {
        Page<OrderReturnReason> pageParams = new Page<>(page, limit);
        PageResult<OrderReturnReasonVo> pageResult = orderReturnReasonService.getOrderReturnReasonPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加退货原因", description = "添加退货原因")
    @PostMapping()
    public Result<String> addOrderReturnReason(@Valid @RequestBody OrderReturnReasonDto dto) {
        orderReturnReasonService.addOrderReturnReason(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新退货原因", description = "更新退货原因")
    @PutMapping()
    public Result<String> updateOrderReturnReason(@Valid @RequestBody OrderReturnReasonDto dto) {
        orderReturnReasonService.updateOrderReturnReason(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除退货原因", description = "删除退货原因")
    @DeleteMapping()
    public Result<String> deleteOrderReturnReason(@RequestBody List<Long> ids) {
        orderReturnReasonService.deleteOrderReturnReason(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}