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.MqMessageDto;
import com.mall.order.domain.entity.MqMessage;
import com.mall.order.domain.vo.MqMessageVo;
import com.mall.order.service.MqMessageService;
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 = "MqMessage", description = "MqMessage相关接口")
@RestController
@RequestMapping("/api/order/mq-message")
@RequiredArgsConstructor
public class MqMessageController {

    private final MqMessageService mqMessageService;

    @Operation(summary = "MqMessage分页查询", description = "MqMessage分页")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<MqMessageVo>> getMqMessagePage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            MqMessageDto dto) {
        Page<MqMessage> pageParams = new Page<>(page, limit);
        PageResult<MqMessageVo> pageResult = mqMessageService.getMqMessagePage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "MqMessage添加", description = "MqMessage添加")
    @PostMapping()
    public Result<String> addMqMessage(@Valid @RequestBody MqMessageDto dto) {
        mqMessageService.addMqMessage(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "MqMessage更新", description = "MqMessage更新")
    @PutMapping()
    public Result<String> updateMqMessage(@Valid @RequestBody MqMessageDto dto) {
        mqMessageService.updateMqMessage(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "MqMessage删除", description = "MqMessage删除")
    @DeleteMapping()
    public Result<String> deleteMqMessage(@RequestBody List<Long> ids) {
        mqMessageService.deleteMqMessage(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
    
}