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.PropertyBuildingsQryDto;
import com.yuchen.saas.park.api.dto.property.PropertyBuildingsSaveDto;
import com.yuchen.saas.park.api.entity.property.PropertyBuildings;
import com.yuchen.saas.park.api.vo.property.PropertyBuildingsListVo;
import com.yuchen.saas.park.service.service.property.PropertyBuildingsService;
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;
import java.util.List;

@Api(tags = "楼栋管理")
@RestController
@RequestMapping("/propertyBuildings")
public class PropertyBuildingsController {
    @Autowired
    private PropertyBuildingsService propertyBuildingsService;

    @PostMapping("/save")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新增", notes = "楼栋新增")
    public R save(@Valid @RequestBody PropertyBuildingsSaveDto saveDto) {
        propertyBuildingsService.saveBuilding(saveDto);
        return R.success();
    }

    @PostMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "列表", notes = "楼栋列表")
    public R<Page<PropertyBuildingsListVo>> list(@RequestBody PropertyBuildingsQryDto propertyBuildingsQryDto) {
        return R.data(propertyBuildingsService.selectPage(propertyBuildingsQryDto));
    }

    @GetMapping("/detail")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "详情", notes = "楼栋详情")
    public R<PropertyBuildingsSaveDto> detail(@RequestParam("id") Long id) {
        return R.data(propertyBuildingsService.getBuildingDetail(id));
    }

    @PostMapping("/delete")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "删除", notes = "楼栋删除")
    public R delete(@Valid @RequestBody CommonIdParam param) {
        return R.data(propertyBuildingsService.del(param.getId()));
    }

    @GetMapping("/getBuildingsByParkId")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "社区ID获取楼栋", notes = "根据社区ID获取楼栋")
    public R<List<PropertyBuildings>> getBuildingsByParkId(@RequestParam("parkId") Long parkId) {
        return R.data(propertyBuildingsService.getAll(parkId));
    }



}
