package cn.iocoder.yudao.module.system.controller.admin.rental;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.rental.vo.rentaldepositrecord.RentalDepositRecordPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.rental.vo.rentaldepositrecord.RentalDepositRecordRespVO;
import cn.iocoder.yudao.module.system.controller.admin.rental.vo.rentaldepositrecord.RentalDepositRecordSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.rental.RentalDepositRecordDO;
import cn.iocoder.yudao.module.system.service.rental.RentalDepositRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - 租赁订单押金记录")
@RestController
@RequestMapping("/system/rental-deposit-record")
@Validated
public class RentalDepositRecordController {

    @Resource
    private RentalDepositRecordService rentalDepositRecordService;

    @PostMapping("/create")
    @Operation(summary = "创建租赁订单押金记录")
    @PreAuthorize("@ss.hasPermission('system:rental-deposit-record:create')")
    public CommonResult<Long> createRentalDepositRecord(@Valid @RequestBody RentalDepositRecordSaveReqVO createReqVO) {
        return success(rentalDepositRecordService.createRentalDepositRecord(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新租赁订单押金记录")
    @PreAuthorize("@ss.hasPermission('system:rental-deposit-record:update')")
    public CommonResult<Boolean> updateRentalDepositRecord(@Valid @RequestBody RentalDepositRecordSaveReqVO updateReqVO) {
        rentalDepositRecordService.updateRentalDepositRecord(updateReqVO);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得租赁订单押金记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('system:rental-deposit-record:query')")
    public CommonResult<RentalDepositRecordRespVO> getRentalDepositRecord(@RequestParam("id") Long id) {
        RentalDepositRecordDO rentalDepositRecord = rentalDepositRecordService.getRentalDepositRecord(id);
        return success(BeanUtils.toBean(rentalDepositRecord, RentalDepositRecordRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得租赁订单押金记录分页")
    @PreAuthorize("@ss.hasPermission('system:rental-deposit-record:query')")
    public CommonResult<PageResult<RentalDepositRecordRespVO>> getRentalDepositRecordPage(@Valid RentalDepositRecordPageReqVO pageReqVO) {
        PageResult<RentalDepositRecordDO> pageResult = rentalDepositRecordService.getRentalDepositRecordPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, RentalDepositRecordRespVO.class));
    }
}