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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.manage.system.api.param.CommonIdParam;
import com.yuchen.saas.park.api.dto.property.PropertyHousesAutoDeductionDto;
import com.yuchen.saas.park.api.dto.property.PropertyHousesBindingQueryDto;
import com.yuchen.saas.park.api.dto.property.PropertyHousesQryDto;
import com.yuchen.saas.park.api.entity.property.PropertyHouses;
import com.yuchen.saas.park.api.vo.property.PropertyHousesBindingVo;
import com.yuchen.saas.park.api.vo.property.PropertyHousesListVo;
import com.yuchen.saas.park.api.vo.property.PropertyHousesTreeVo;
import com.yuchen.saas.park.api.vo.property.PropertyHousesVo;
import com.yuchen.saas.park.service.service.property.PropertyHousesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "房源管理")
@RestController
@RequestMapping("/propertyHouses")
public class PropertyHousesController {
    @Autowired
    private PropertyHousesService propertyHousesService;

    @PostMapping("/save")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新增", notes = "房源新增")
    public R save(@Valid @RequestBody PropertyHouses propertyHouses) {
        return R.status(propertyHousesService.saveHouse(propertyHouses));
    }

    @PostMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "列表", notes = "房源列表")
    public R<Page<PropertyHousesListVo>> list(@RequestBody PropertyHousesQryDto propertyHousesQrydto) {
        return R.data(propertyHousesService.selectPage(propertyHousesQrydto));
    }

    @GetMapping("/detail")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "详情", notes = "房源详情")
    public R<PropertyHousesVo> detail(@RequestParam("id") Long id) {
        return R.data(propertyHousesService.getPropertyHousesDetail(id));
    }

    @PostMapping("/delete")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "删除", notes = "房源删除")
    public R delete(@Valid @RequestBody CommonIdParam param) {
        return R.data(propertyHousesService.removeById(param.getId()));
    }


    @GetMapping("/getHousesTree")
    @ApiOperationSupport(order = 10)
    @ApiOperation(value = "房源树形结构", notes = "根据园区id获取楼栋、单元、楼层、房间树形结构")
    public R<PropertyHousesTreeVo> getHousesTree(@RequestParam(value = "parkId", required = false) Long parkId) {
        return R.data(propertyHousesService.getHousesTree(parkId));
    }

    @GetMapping("/getHousesTreePoly")
    @ApiOperationSupport(order = 10)
    @ApiOperation(value = "房源树形结构（保利）", notes = "根据园区id获取楼栋、单元、楼层、房间树形结构")
    public R<PropertyHousesTreeVo> getHousesTreePoly(@RequestParam(value = "parkId", required = false) Long parkId) {
        return R.data(propertyHousesService.getHousesTreePoly(parkId));
    }

    @GetMapping("/getSpaceTreePoly")
    @ApiOperationSupport(order = 11)
    @ApiOperation(value = "空间树（保利）", notes = "根据园区id获取楼栋、单元、楼层、房间、点位树形结构")
    public R<PropertyHousesTreeVo> getSpaceTreePoly(@RequestParam(value = "parkId", required = false) Long parkId) {
        return R.data(propertyHousesService.getSpaceTreePoly(parkId));
    }

    @PostMapping("/autoDeduction")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "自动扣款,开通/取消", notes = "自动扣款,开通/取消")
    public R autoDeduction(@Valid @RequestBody PropertyHousesAutoDeductionDto param) {
        return R.status(propertyHousesService.autoDeduction(param));
    }

    @GetMapping("/listByBinding")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "自动扣款绑定房源列", notes = "自动扣款绑定房源列")
    public R<Page<PropertyHousesBindingVo>> listByBinding(@Valid PropertyHousesBindingQueryDto param) {
        return R.data(propertyHousesService.listByBinding(param));
    }

}
