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

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.manage.system.api.param.CommonIdParam;
import com.yuchen.saas.park.api.entity.property.PropertyBuildingUnit;
import com.yuchen.saas.park.service.service.property.PropertyBuildingUnitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.nest.springwrap.core.mp.support.Condition;
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;

    /**
     * @description:
     * @author: 洪铭铭
     * @time: 2024/6/4 17:32
     */

@Api(tags = "楼栋单元管理")
@RestController
@RequestMapping("/propertyBuildingUnit")
public class PropertyBuildingUnitController {
    @Autowired
    private PropertyBuildingUnitService propertyBuildingUnitService;

    @PostMapping("/save")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新增", notes = "楼栋单元新增")
    public R save(@Valid @RequestBody PropertyBuildingUnit propertyBuildingUnit) {
        return R.status(propertyBuildingUnitService.saveOrUpdate(propertyBuildingUnit));
    }

    @PostMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "列表", notes = "楼栋单元列表")
    public R<List<PropertyBuildingUnit>> list(@Valid @RequestBody PropertyBuildingUnit propertyBuildingUnit) {
        return R.data(propertyBuildingUnitService.list(Condition.getQueryWrapper(propertyBuildingUnit)));
    }
    @PostMapping("/update")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "修改", notes = "楼栋单元修改")
    public R update(@Valid @RequestBody PropertyBuildingUnit propertyBuildingUnit) {
        return R.status(propertyBuildingUnitService.saveOrUpdate(propertyBuildingUnit));
    }

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

    @GetMapping("/detail")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "详情", notes = "楼栋单元详情")
    public R<PropertyBuildingUnit> detail(@RequestParam("id") Long id) {
        return R.data(propertyBuildingUnitService.getById(id));
    }

    @GetMapping("/getUnitsByBuildingId")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "建筑ID获取单元", notes = "根据建筑ID获取单元")
    public R<List<PropertyBuildingUnit>> getUnitsByBuildingId(@RequestParam("buildingId") Long buildingId) {
        return R.data(propertyBuildingUnitService.getUnitsByBuildingId(buildingId));
    }



}


