package cn.iocoder.yudao.module.system.api.rental;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.api.rental.dto.RentalDepositRecordDTO;
import cn.iocoder.yudao.module.system.controller.admin.rental.vo.rentaldepositrecord.RentalDepositAmountReqVO;
import cn.iocoder.yudao.module.system.controller.admin.rental.vo.rentaldepositrecord.RentalDepositRecordSaveReqVO;
import cn.iocoder.yudao.module.system.service.rental.RentalDepositRecordService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

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

@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class RentalDepositRecordApiImpl implements RentalDepositRecordApi {

    @Resource
    private RentalDepositRecordService rentalDepositRecordService;

    @Override
    public CommonResult<Long> create(RentalDepositRecordDTO createReqVO) {
        RentalDepositRecordSaveReqVO depositRecord = BeanUtils.toBean(createReqVO, RentalDepositRecordSaveReqVO.class);
        return success(rentalDepositRecordService.createRentalDepositRecord(depositRecord));
    }

    @Override
    public CommonResult<Map<String, BigDecimal>> getRecordAmount(String orderNo) {
        RentalDepositAmountReqVO reqVO = rentalDepositRecordService.getRentalDepositRecordAmount(orderNo, false);
        Map<String, BigDecimal> result = new HashMap<>();
        result.put("receivedAmount", reqVO.getReceivedAmount());
        result.put("refundAmount", reqVO.getRefundAmount());
        return success(result);
    }
}
