package cn.bunny.services.controller.financial;

import cn.bunny.dao.dto.financial.savingGoal.SavingGoalAddDto;
import cn.bunny.dao.dto.financial.savingGoal.SavingGoalDto;
import cn.bunny.dao.dto.financial.savingGoal.SavingGoalUpdateDto;
import cn.bunny.dao.entity.financial.SavingGoal;
import cn.bunny.dao.pojo.result.PageResult;
import cn.bunny.dao.pojo.result.Result;
import cn.bunny.dao.pojo.result.ResultCodeEnum;
import cn.bunny.dao.vo.financial.admin.SavingGoalVo;
import cn.bunny.services.service.financial.SavingGoalService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * <p>
 * 用户储值表 前端控制器
 * </p>
 *
 * @author Bunny
 * @since 2024-11-11 16:49:29
 */
@Tag(name = "用户储值", description = "用户储值相关接口")
@RestController
@RequestMapping("admin/savingGoal")
public class SavingGoalController {

    @Autowired
    private SavingGoalService savingGoalService;

    @Operation(summary = "分页查询用户储值", description = "分页查询用户储值")
    @GetMapping("getSavingGoalList/{page}/{limit}")
    public Mono<Result<PageResult<SavingGoalVo>>> getSavingGoalList(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            SavingGoalDto dto) {
        Page<SavingGoal> pageParams = new Page<>(page, limit);
        PageResult<SavingGoalVo> pageResult = savingGoalService.getSavingGoalList(pageParams, dto);
        return Mono.just(Result.success(pageResult));
    }

    @Operation(summary = "添加用户储值", description = "添加用户储值")
    @PostMapping("addSavingGoal")
    public Mono<Result<String>> addSavingGoal(@Valid @RequestBody SavingGoalAddDto dto) {
        savingGoalService.addSavingGoal(dto);
        return Mono.just(Result.success(ResultCodeEnum.ADD_SUCCESS));
    }

    @Operation(summary = "更新用户储值", description = "更新用户储值")
    @PutMapping("updateSavingGoal")
    public Mono<Result<String>> updateSavingGoal(@Valid @RequestBody SavingGoalUpdateDto dto) {
        savingGoalService.updateSavingGoal(dto);
        return Mono.just(Result.success(ResultCodeEnum.UPDATE_SUCCESS));
    }

    @Operation(summary = "删除用户储值", description = "删除用户储值")
    @DeleteMapping("deleteSavingGoal")
    public Mono<Result<String>> deleteSavingGoal(@RequestBody List<Long> ids) {
        savingGoalService.deleteSavingGoal(ids);
        return Mono.just(Result.success(ResultCodeEnum.DELETE_SUCCESS));
    }
}
