package cn.bunny.services.controller.financial;

import cn.bunny.dao.dto.financial.debtTracking.DebtTrackingAddDto;
import cn.bunny.dao.dto.financial.debtTracking.DebtTrackingDto;
import cn.bunny.dao.dto.financial.debtTracking.DebtTrackingUpdateDto;
import cn.bunny.dao.entity.financial.DebtTracking;
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.DebtTrackingVo;
import cn.bunny.services.service.financial.DebtTrackingService;
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:36:31
 */
@Tag(name = "债务追踪", description = "债务追踪相关接口")
@RestController
@RequestMapping("admin/debtTracking")
public class DebtTrackingController {

    @Autowired
    private DebtTrackingService debtTrackingService;

    @Operation(summary = "分页查询债务追踪", description = "分页查询债务追踪")
    @GetMapping("getDebtTrackingList/{page}/{limit}")
    public Mono<Result<PageResult<DebtTrackingVo>>> getDebtTrackingList(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            DebtTrackingDto dto) {
        Page<DebtTracking> pageParams = new Page<>(page, limit);
        PageResult<DebtTrackingVo> pageResult = debtTrackingService.getDebtTrackingList(pageParams, dto);
        return Mono.just(Result.success(pageResult));
    }

    @Operation(summary = "添加债务追踪", description = "添加债务追踪")
    @PostMapping("addDebtTracking")
    public Mono<Result<String>> addDebtTracking(@Valid @RequestBody DebtTrackingAddDto dto) {
        debtTrackingService.addDebtTracking(dto);
        return Mono.just(Result.success(ResultCodeEnum.ADD_SUCCESS));
    }

    @Operation(summary = "更新债务追踪", description = "更新债务追踪")
    @PutMapping("updateDebtTracking")
    public Mono<Result<String>> updateDebtTracking(@Valid @RequestBody DebtTrackingUpdateDto dto) {
        debtTrackingService.updateDebtTracking(dto);
        return Mono.just(Result.success(ResultCodeEnum.UPDATE_SUCCESS));
    }

    @Operation(summary = "删除债务追踪", description = "删除债务追踪")
    @DeleteMapping("deleteDebtTracking")
    public Mono<Result<String>> deleteDebtTracking(@RequestBody List<Long> ids) {
        debtTrackingService.deleteDebtTracking(ids);
        return Mono.just(Result.success(ResultCodeEnum.DELETE_SUCCESS));
    }
}
