package cn.bunny.services.controller.financial;

import cn.bunny.dao.dto.financial.budgetCategory.BudgetCategoryAddDto;
import cn.bunny.dao.dto.financial.budgetCategory.BudgetCategoryDto;
import cn.bunny.dao.dto.financial.budgetCategory.BudgetCategoryUpdateDto;
import cn.bunny.dao.entity.financial.BudgetCategory;
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.BudgetCategoryParentVo;
import cn.bunny.dao.vo.financial.admin.BudgetCategoryVo;
import cn.bunny.services.service.financial.BudgetCategoryService;
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 15:36:57
 */
@Tag(name = "预算分类表", description = "预算分类表相关接口")
@RestController
@RequestMapping("admin/budgetCategory")
public class BudgetCategoryController {

    @Autowired
    private BudgetCategoryService budgetCategoryService;

    @Operation(summary = "分页查询预算分类表", description = "分页查询预算分类表")
    @GetMapping("getBudgetCategoryList/{page}/{limit}")
    public Mono<Result<PageResult<BudgetCategoryVo>>> getBudgetCategoryList(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            BudgetCategoryDto dto) {
        Page<BudgetCategory> pageParams = new Page<>(page, limit);
        PageResult<BudgetCategoryVo> pageResult = budgetCategoryService.getBudgetCategoryList(pageParams, dto);
        return Mono.just(Result.success(pageResult));
    }

    @Operation(summary = "返回所有父级对象", description = "返回所有父级对象")
    @GetMapping("noManage/getAllParentList")
    public Mono<Result<List<BudgetCategoryParentVo>>> getAllParentList() {
        List<BudgetCategoryParentVo> voList = budgetCategoryService.getAllParentList();
        return Mono.just(Result.success(voList));
    }

    @Operation(summary = "添加预算分类表", description = "添加预算分类表")
    @PostMapping("addBudgetCategory")
    public Mono<Result<String>> addBudgetCategory(@Valid @RequestBody BudgetCategoryAddDto dto) {
        budgetCategoryService.addBudgetCategory(dto);
        return Mono.just(Result.success(ResultCodeEnum.ADD_SUCCESS));
    }

    @Operation(summary = "更新预算分类表", description = "更新预算分类表")
    @PutMapping("updateBudgetCategory")
    public Mono<Result<String>> updateBudgetCategory(@Valid @RequestBody BudgetCategoryUpdateDto dto) {
        budgetCategoryService.updateBudgetCategory(dto);
        return Mono.just(Result.success(ResultCodeEnum.UPDATE_SUCCESS));
    }

    @Operation(summary = "删除预算分类表", description = "删除预算分类表")
    @DeleteMapping("deleteBudgetCategory")
    public Mono<Result<String>> deleteBudgetCategory(@RequestBody List<Long> ids) {
        budgetCategoryService.deleteBudgetCategory(ids);
        return Mono.just(Result.success(ResultCodeEnum.DELETE_SUCCESS));
    }
}
