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.OrderOperateHistoryDto;
import com.mall.order.domain.entity.OrderOperateHistory;
import com.mall.order.domain.vo.OrderOperateHistoryVo;
import com.mall.order.service.OrderOperateHistoryService;
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-operate-history")
@RequiredArgsConstructor
public class OrderOperateHistoryController {

    private final OrderOperateHistoryService orderOperateHistoryService;

    @Operation(summary = "分页查询订单操作历史记录", description = "分页订单操作历史记录")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<OrderOperateHistoryVo>> getOrderOperateHistoryPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            OrderOperateHistoryDto dto) {
        Page<OrderOperateHistory> pageParams = new Page<>(page, limit);
        PageResult<OrderOperateHistoryVo> pageResult = orderOperateHistoryService.getOrderOperateHistoryPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加订单操作历史记录", description = "添加订单操作历史记录")
    @PostMapping()
    public Result<String> addOrderOperateHistory(@Valid @RequestBody OrderOperateHistoryDto dto) {
        orderOperateHistoryService.addOrderOperateHistory(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新订单操作历史记录", description = "更新订单操作历史记录")
    @PutMapping()
    public Result<String> updateOrderOperateHistory(@Valid @RequestBody OrderOperateHistoryDto dto) {
        orderOperateHistoryService.updateOrderOperateHistory(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除订单操作历史记录", description = "删除订单操作历史记录")
    @DeleteMapping()
    public Result<String> deleteOrderOperateHistory(@RequestBody List<Long> ids) {
        orderOperateHistoryService.deleteOrderOperateHistory(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}