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.*;
import com.yuchen.saas.park.api.vo.property.*;
import com.yuchen.saas.park.service.service.property.PropertyCashDeskService;
import com.yuchen.saas.park.service.service.property.bill.PropertyBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "收银台")
@RestController
@RequestMapping("/propertyCashDesk")
public class PropertyCashDeskController {
    @Resource
    private PropertyBillService propertyBillService;
    @Resource
    private PropertyCashDeskService propertyCashDeskService;

    @PostMapping("/list")
    @ApiOperation(value = "收费列表")
    public R<Page<PropertyBillListVo>> list(@RequestBody PropertyBillPageQryDto propertyBillPageQryDto) {
        return R.data(propertyCashDeskService.selectChargeBillPage(propertyBillPageQryDto));
    }


    @PostMapping("/chargeFeesView")
    @ApiOperation(value = "线下收费详情")
    public R<PropertyChargeFeesViewVo> chargeFeesView(@RequestBody PropertyChargeFeesViewDto dto) {
        return R.data(propertyCashDeskService.chargeFeesView(dto));
    }

    @PostMapping("/chargeFeesOffline")
    @ApiOperation(value = "线下收费提交")
    public R chargeFeesOffline(@Validated(PropertyChargeFeesOfflineDto.Default.class)
                               @RequestBody PropertyChargeFeesOfflineDto dto) {
        propertyCashDeskService.submitChargeFeesOffline(dto);
        return R.success();
    }

    @GetMapping("/cashDeskHouseInfo")
    @ApiOperation(value = "收银台首页房源信息")
    public R<PropertyCashDeskHouseInfoVo> cashDeskHouseInfo(@RequestParam("houseId") Long houseId) {
        return R.data(propertyCashDeskService.cashDeskHouseInfo(houseId));
    }


    @PostMapping("/cashDeskBillInfo")
    @ApiOperation(value = "收银台首页收费统计信息")
    public R<PropertyCashDeskInfoVo> cashDeskBillInfo(@Valid @RequestBody PropertyCashDeskBaseDto cashDeskBaseDto) {
        return R.data(propertyCashDeskService.cashDeskBillInfo(cashDeskBaseDto));
    }


    @PostMapping("/billReadjustDetail")
    @ApiOperation(value = "费用调整详情")
    public R<List<PropertyBillListVo>> billReadjustDetail(@Valid @RequestBody PropertyCashDeskBaseDto cashDeskBaseDto) {
        return R.data(propertyCashDeskService.billReadjustDetail(cashDeskBaseDto));
    }

    @PostMapping("/billReadjust")
    @ApiOperation(value = "费用调整")
    public R billReadjust(@Valid @RequestBody PropertyBillReadjustDto billReadjustDto) {
        propertyCashDeskService.billReadjust(billReadjustDto);
        return R.success();
    }


    @PostMapping("/tempBillView")
    @ApiOperation(value = "临时收费预览")
    public R<List<PropertyBillTempBillViewVo>> tempBillView(@Valid @RequestBody CommonIdParam idParam) {
        return R.data(propertyCashDeskService.tempBillView(idParam.getId()));
    }

    @PostMapping("/tempBillSave")
    @ApiOperation(value = "临时收费保存")
    public R createTempBill(@Valid @RequestBody PropertyCashDeskTempBillDto dto) {
        propertyCashDeskService.tempBillSave(dto);
        return R.success();
    }


    @PostMapping("/billSplit")
    @ApiOperation(value = "账单拆分")
    public R billSplit(@Valid @RequestBody PropertyBillSplitDto dto) {
        propertyCashDeskService.billSplit(dto);
        return R.success();
    }

    @PostMapping("/billBeforehand")
    @ApiOperation(value = "预收")
    public R billBeforehand(@Valid @RequestBody PropertyBillBeforehandDto dto) {
        propertyCashDeskService.billBeforehand(dto);
        return R.success();
    }

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

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

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

    @PostMapping("/calcBreachAmt")
    @ApiOperation(value = "滞纳金计算")
    public R calcBreachAmt(@Valid @RequestBody PropertyCalcBreachAmtDto dto) {
        propertyBillService.calcBreachAmt(dto);
        return R.success();
    }

    @GetMapping("/getBeforeFeeList")
    @ApiOperation(value = "收费标准预收列表")
    public R<PropertyBeforeFeeListVo> getBeforeFeeList(@RequestParam("parkId") Long parkId
            ,@RequestParam("houseId") Long houseId, @RequestParam("feeItemId") Long feeItemId, @RequestParam("num") Integer num) {
        propertyCashDeskService.getBeforeFeeList(parkId,houseId,feeItemId, num);
        // TODO tucq
        return R.success();
    }


}
