package cn.bunny.services.controller.financial;

import cn.bunny.dao.dto.financial.category.admin.CategoryAddDto;
import cn.bunny.dao.dto.financial.category.admin.CategoryDto;
import cn.bunny.dao.dto.financial.category.admin.CategoryUpdateDto;
import cn.bunny.dao.dto.financial.category.user.CategoryUserAddDto;
import cn.bunny.dao.dto.financial.category.user.CategoryUserDto;
import cn.bunny.dao.dto.financial.category.user.CategoryUserUpdateDto;
import cn.bunny.dao.entity.financial.Category;
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.CategoryVo;
import cn.bunny.dao.vo.financial.user.CategoryUserVo;
import cn.bunny.services.service.financial.CategoryService;
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-08 10:29:58
 */
@Tag(name = "分类信息", description = "分类信息相关接口")
@RestController
@RequestMapping("admin/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @Operation(summary = "用户分类分页查询分类信息", description = "用户分类分页查询分类信息")
    @GetMapping("noManage/getCategoryUserList/{page}/{limit}")
    public Mono<Result<PageResult<CategoryUserVo>>> getCategoryUserList(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            CategoryUserDto dto) {
        Page<Category> pageParams = new Page<>(page, limit);
        PageResult<CategoryUserVo> pageResult = categoryService.getCategoryUserList(pageParams, dto);
        return Mono.just(Result.success(pageResult));
    }

    @Operation(summary = "查询当前用户下所有的分类", description = "查询当前用户下所有的分类")
    @GetMapping("noManage/getCategoryUserAllList")
    public Mono<Result<List<CategoryUserVo>>> getCategoryUserAllList() {
        List<CategoryUserVo> voList = categoryService.getCategoryUserAllList();
        return Mono.just(Result.success(voList));
    }

    @Operation(summary = "用戶分类添加分类信息", description = "用戶分类添加分类信息")
    @PostMapping("noManage/addCategoryUser")
    public Mono<Result<String>> addCategoryUser(@Valid @RequestBody CategoryUserAddDto dto) {
        categoryService.addCategoryUser(dto);
        return Mono.just(Result.success(ResultCodeEnum.ADD_SUCCESS));
    }

    @Operation(summary = "用户分类更新分类信息", description = "用户分类更新分类信息")
    @PutMapping("noManage/updateCategoryUser")
    public Mono<Result<String>> updateCategoryUser(@Valid @RequestBody CategoryUserUpdateDto dto) {
        categoryService.updateCategoryUser(dto);
        return Mono.just(Result.success(ResultCodeEnum.UPDATE_SUCCESS));
    }

    @Operation(summary = "用户分类删除分类信息", description = "用户分类删除分类信息")
    @DeleteMapping("noManage/deleteCategoryUser")
    public Mono<Result<String>> deleteCategoryUser(@RequestBody List<Long> ids) {
        categoryService.deleteCategoryUser(ids);
        return Mono.just(Result.success(ResultCodeEnum.DELETE_SUCCESS));
    }

    @Operation(summary = "分页查询分类信息", description = "分页查询分类信息")
    @GetMapping("getCategoryList/{page}/{limit}")
    public Mono<Result<PageResult<CategoryVo>>> getCategoryList(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            CategoryDto dto) {
        Page<Category> pageParams = new Page<>(page, limit);
        PageResult<CategoryVo> pageResult = categoryService.getCategoryList(pageParams, dto);
        return Mono.just(Result.success(pageResult));
    }

    @Operation(summary = "添加分类信息", description = "添加分类信息")
    @PostMapping("addCategory")
    public Mono<Result<String>> addCategory(@Valid @RequestBody CategoryAddDto dto) {
        categoryService.addCategory(dto);
        return Mono.just(Result.success(ResultCodeEnum.ADD_SUCCESS));
    }

    @Operation(summary = "更新分类信息", description = "更新分类信息")
    @PutMapping("updateCategory")
    public Mono<Result<String>> updateCategory(@Valid @RequestBody CategoryUpdateDto dto) {
        categoryService.updateCategory(dto);
        return Mono.just(Result.success(ResultCodeEnum.UPDATE_SUCCESS));
    }

    @Operation(summary = "删除分类信息", description = "删除分类信息")
    @DeleteMapping("deleteCategory")
    public Mono<Result<String>> deleteCategory(@RequestBody List<Long> ids) {
        categoryService.deleteCategory(ids);
        return Mono.just(Result.success(ResultCodeEnum.DELETE_SUCCESS));
    }
}
