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.RefundInfoDto;
import com.mall.order.domain.entity.RefundInfo;
import com.mall.order.domain.vo.RefundInfoVo;
import com.mall.order.service.RefundInfoService;
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/refund-info")
@RequiredArgsConstructor
public class RefundInfoController {

    private final RefundInfoService refundInfoService;

    @Operation(summary = "分页查询退款信息", description = "分页退款信息")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<RefundInfoVo>> getRefundInfoPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            RefundInfoDto dto) {
        Page<RefundInfo> pageParams = new Page<>(page, limit);
        PageResult<RefundInfoVo> pageResult = refundInfoService.getRefundInfoPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加退款信息", description = "添加退款信息")
    @PostMapping()
    public Result<String> addRefundInfo(@Valid @RequestBody RefundInfoDto dto) {
        refundInfoService.addRefundInfo(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新退款信息", description = "更新退款信息")
    @PutMapping()
    public Result<String> updateRefundInfo(@Valid @RequestBody RefundInfoDto dto) {
        refundInfoService.updateRefundInfo(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除退款信息", description = "删除退款信息")
    @DeleteMapping()
    public Result<String> deleteRefundInfo(@RequestBody List<Long> ids) {
        refundInfoService.deleteRefundInfo(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}