package com.mall.member.controller;

import com.mall.member.domain.dto.IntegrationChangeHistoryDto;
import com.mall.member.domain.entity.IntegrationChangeHistory;
import com.mall.member.domain.vo.IntegrationChangeHistoryVo;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import com.mall.member.service.IntegrationChangeHistoryService;
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 java.util.List;

/**
 * <p>
 * 积分变化历史记录 前端控制器
 * </p>
 *
 * @author Bunny
 * @since 2025-07-05 19:30:06
 */
@Tag(name = "积分变化历史记录", description = "积分变化历史记录相关接口")
@RestController
@RequestMapping("/api/member/integration-change-history")
@RequiredArgsConstructor
public class IntegrationChangeHistoryController {

    private final IntegrationChangeHistoryService integrationChangeHistoryService;

    @Operation(summary = "分页查询积分变化历史记录", description = "分页积分变化历史记录")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<IntegrationChangeHistoryVo>> getIntegrationChangeHistoryPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            IntegrationChangeHistoryDto dto) {
        Page<IntegrationChangeHistory> pageParams = new Page<>(page, limit);
        PageResult<IntegrationChangeHistoryVo> pageResult = integrationChangeHistoryService.getIntegrationChangeHistoryPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加积分变化历史记录", description = "添加积分变化历史记录")
    @PostMapping()
    public Result<String> addIntegrationChangeHistory(@Valid @RequestBody IntegrationChangeHistoryDto dto) {
            integrationChangeHistoryService.addIntegrationChangeHistory(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新积分变化历史记录", description = "更新积分变化历史记录")
    @PutMapping()
    public Result<String> updateIntegrationChangeHistory(@Valid @RequestBody IntegrationChangeHistoryDto dto) {
            integrationChangeHistoryService.updateIntegrationChangeHistory(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除积分变化历史记录", description = "删除积分变化历史记录")
    @DeleteMapping()
    public Result<String> deleteIntegrationChangeHistory(@RequestBody List<Long> ids) {
            integrationChangeHistoryService.deleteIntegrationChangeHistory(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}