package cn.bunny.services.controller.financial;

import cn.bunny.dao.dto.financial.bill.admin.BillAddDto;
import cn.bunny.dao.dto.financial.bill.admin.BillDto;
import cn.bunny.dao.dto.financial.bill.admin.BillUpdateDto;
import cn.bunny.dao.dto.financial.bill.user.BillUserAddDto;
import cn.bunny.dao.dto.financial.bill.user.BillUserDto;
import cn.bunny.dao.dto.financial.bill.user.BillUserUpdateDto;
import cn.bunny.dao.entity.financial.Bill;
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.BillVo;
import cn.bunny.dao.vo.financial.user.BillUserVo;
import cn.bunny.services.service.financial.BillService;
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-07 16:49:19
 */
@Tag(name = "账单信息", description = "账单信息相关接口")
@RestController
@RequestMapping("admin/bill")
public class BillController {

    @Autowired
    private BillService billService;

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

    @Operation(summary = "用户添加账单信息", description = "用户添加账单信息")
    @PostMapping("noManage/addUserBill")
    public Mono<Result<String>> addUserBill(@Valid @RequestBody BillUserAddDto dto) {
        billService.addUserBill(dto);
        return Mono.just(Result.success(ResultCodeEnum.ADD_SUCCESS));
    }

    @Operation(summary = "用户更新账单信息", description = "用户更新账单信息")
    @PutMapping("noManage/updateUserBill")
    public Mono<Result<String>> updateUserBill(@Valid @RequestBody BillUserUpdateDto dto) {
        billService.updateUserBill(dto);
        return Mono.just(Result.success(ResultCodeEnum.UPDATE_SUCCESS));
    }

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

    @Operation(summary = "分页查询账单信息", description = "分页查询账单信息")
    @GetMapping("getBillList/{page}/{limit}")
    public Mono<Result<PageResult<BillVo>>> getBillList(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            BillDto dto) {
        Page<Bill> pageParams = new Page<>(page, limit);
        PageResult<BillVo> pageResult = billService.getBillList(pageParams, dto);
        return Mono.just(Result.success(pageResult));
    }

    @Operation(summary = "添加账单信息", description = "添加账单信息")
    @PostMapping("addBill")
    public Mono<Result<String>> addBill(@Valid @RequestBody BillAddDto dto) {
        billService.addBill(dto);
        return Mono.just(Result.success(ResultCodeEnum.ADD_SUCCESS));
    }

    @Operation(summary = "更新账单信息", description = "更新账单信息")
    @PutMapping("updateBill")
    public Mono<Result<String>> updateBill(@Valid @RequestBody BillUpdateDto dto) {
        billService.updateBill(dto);
        return Mono.just(Result.success(ResultCodeEnum.UPDATE_SUCCESS));
    }

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