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

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuchen.saas.park.api.dto.property.PropertyBillPageQryDto;
import com.yuchen.saas.park.api.entity.property.PropertyBillPay;
import com.yuchen.saas.park.api.enums.property.BillStatusEnum;
import com.yuchen.saas.park.api.enums.property.PayStatusEnum;
import com.yuchen.saas.park.api.vo.property.PropertyAppPayBilListVo;
import com.yuchen.saas.park.service.service.property.PropertyAppCustomerService;
import com.yuchen.saas.park.service.service.property.bill.PropertyBillSearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.nest.springwrap.core.log.exception.ServiceException;
import org.nest.springwrap.core.tool.api.R;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "小程序端物业缴费")
@RestController
@RequestMapping("/app/billPayment")
public class PropertyAppBillPaymentController {
    @Resource
    private PropertyBillSearchService propertyBillSearchService;
    @Resource
    private PropertyAppCustomerService propertyAppCustomerService;

    @GetMapping("/getCustomerId")
    @ApiOperation(value = "获取物业客户id")
    public R<Long> getCustomerId(@RequestParam("isPersonal") Integer isPersonal) {
        return R.data(propertyAppCustomerService.getAppPropertyCustomerArchivesId(isPersonal));
    }

    @PostMapping("/getPayBillList")
    @ApiOperation(value = "app端账单缴费列表")
    public R<Page<PropertyAppPayBilListVo>> getPayBillList(@RequestBody PropertyBillPageQryDto qryDto) {
        if (Func.isEmpty(qryDto.getParkId())) {
            throw new ServiceException("园区id不能为空");
        }
        if (Func.isEmpty(qryDto.getHouseId()) && Func.isEmpty(qryDto.getCustomerId())) {
            throw new ServiceException("房源id和客户id不能同时为空");
        }
        qryDto.setBillStatus(BillStatusEnum.YES_OUT.getValue());
        qryDto.setPayStatusList(PayStatusEnum.getNeedPayStatus());
        return R.data(propertyBillSearchService.selectPageAppPayBill(qryDto));
    }

    @GetMapping("/getPayBillId")
    @ApiOperation(value = "获取缴费id")
    public R<Long> getPayBillId() {
        return R.data(IdWorker.getId(new PropertyBillPay()));
    }


}
