package com.mall.member.controller;

import com.mall.member.domain.dto.GrowthChangeHistoryDto;
import com.mall.member.domain.entity.GrowthChangeHistory;
import com.mall.member.domain.vo.GrowthChangeHistoryVo;
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.GrowthChangeHistoryService;
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/growth-change-history")
@RequiredArgsConstructor
public class GrowthChangeHistoryController {

    private final GrowthChangeHistoryService growthChangeHistoryService;

    @Operation(summary = "分页查询成长值变化历史记录", description = "分页成长值变化历史记录")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<GrowthChangeHistoryVo>> getGrowthChangeHistoryPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            GrowthChangeHistoryDto dto) {
        Page<GrowthChangeHistory> pageParams = new Page<>(page, limit);
        PageResult<GrowthChangeHistoryVo> pageResult = growthChangeHistoryService.getGrowthChangeHistoryPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加成长值变化历史记录", description = "添加成长值变化历史记录")
    @PostMapping()
    public Result<String> addGrowthChangeHistory(@Valid @RequestBody GrowthChangeHistoryDto dto) {
            growthChangeHistoryService.addGrowthChangeHistory(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新成长值变化历史记录", description = "更新成长值变化历史记录")
    @PutMapping()
    public Result<String> updateGrowthChangeHistory(@Valid @RequestBody GrowthChangeHistoryDto dto) {
            growthChangeHistoryService.updateGrowthChangeHistory(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除成长值变化历史记录", description = "删除成长值变化历史记录")
    @DeleteMapping()
    public Result<String> deleteGrowthChangeHistory(@RequestBody List<Long> ids) {
            growthChangeHistoryService.deleteGrowthChangeHistory(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}