package com.yuchen.saas.park.service.controller.property;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuchen.saas.manage.system.api.param.CommonIdParam;
import com.yuchen.saas.park.api.dto.property.PropertyDepositQryDto;
import com.yuchen.saas.park.api.dto.property.PropertyDepositSaveDto;
import com.yuchen.saas.park.api.vo.property.PropertyDepositDetailVo;
import com.yuchen.saas.park.api.vo.property.PropertyDepositListVo;
import com.yuchen.saas.park.service.service.property.PropertyDepositService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

@Api(tags = "押金管理")
@RestController
@RequestMapping("/propertyDeposit")
public class PropertyDepositController {
    @Resource
    private PropertyDepositService propertyDepositService;

    @PostMapping("/save")
    @ApiOperation(value = "保存")
    public R save(@RequestBody PropertyDepositSaveDto depositSaveDto) {
        propertyDepositService.saveDeposit(depositSaveDto);
        return R.success();
    }

    @PostMapping("/list")
    @ApiOperation(value = "列表")
    public R<Page<PropertyDepositListVo>> list(@RequestBody PropertyDepositQryDto qryDto) {
        return R.data(propertyDepositService.selectPage(qryDto));
    }

    @PostMapping("/detail")
    @ApiOperation(value = "详情")
    public R<PropertyDepositDetailVo> detail(@Valid @RequestBody CommonIdParam idParam) {
        return R.data( propertyDepositService.detail(idParam.getId()));
    }

    @PostMapping("/freeze")
    @ApiOperation(value = "冻结")
    public R freeze(@Valid @RequestBody CommonIdParam idParam) {
        propertyDepositService.freezeDeposit(idParam.getId());
        return R.success();
    }

    @PostMapping("/unfreeze")
    @ApiOperation(value = "解冻")
    public R unfreeze(@Valid @RequestBody CommonIdParam idParam) {
        propertyDepositService.unfreezeDeposit(idParam.getId());
        return R.success();
    }


    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    public R delete(@Valid @RequestBody CommonIdParam idParam) {
        propertyDepositService.deleteDeposit(idParam.getId());
        return R.success();
    }

    @PostMapping("/refund")
    @ApiOperation(value = "退费")
    public R refund(@RequestBody PropertyDepositSaveDto depositSaveDto) {
        propertyDepositService.refund(depositSaveDto);
        return R.success();
    }



}
