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.PropertyBuildingsLevelQryDto;
import com.yuchen.saas.park.api.entity.property.PropertyBuildingsLevel;
import com.yuchen.saas.park.service.service.property.PropertyBuildingsLevelService;
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("/propertyBuildingsLevel")
public class PropertyBuildingsLevelController {
    @Autowired
    private PropertyBuildingsLevelService propertyBuildingsLevelService;

    @PostMapping("/save")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新增", notes = "楼层新增")
    public R save(@Valid @RequestBody PropertyBuildingsLevel propertyBuildingsLevel) {
        return R.status(propertyBuildingsLevelService.save(propertyBuildingsLevel));
    }

    @PostMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "列表", notes = "楼层列表")
    public R<Page<PropertyBuildingsLevel>> list(@RequestBody PropertyBuildingsLevelQryDto propertyBuildingsLevelQryDto) {
        return R.data(propertyBuildingsLevelService.selectPage(propertyBuildingsLevelQryDto));
    }
    @PostMapping("/update")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "修改", notes = "楼层修改")
    public R update(@Valid @RequestBody PropertyBuildingsLevel propertyBuildingsLevel) {
        return R.status(propertyBuildingsLevelService.saveOrUpdate(propertyBuildingsLevel));
    }

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

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

    @GetMapping("/getLevelsByBuildingId")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "建筑ID获取楼层", notes = "根据建筑ID获取楼层")
    public R<List<PropertyBuildingsLevel>> getLevelsByBuildingId(@RequestParam("buildingId") Long buildingId) {
        return R.data(propertyBuildingsLevelService.getLevelsByBuildingId(buildingId));
    }

    @GetMapping("/getLevelsByBuildingAndUnitId")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "建筑和单元ID获取楼层", notes = "根据建筑ID和单元ID获取楼层")
    public R<List<PropertyBuildingsLevel>> getLevelsByBuildingAndUnitId(@RequestParam("buildingId") Long buildingId, @RequestParam("buildingUnitId") Long buildingUnitId) {
        return R.data(propertyBuildingsLevelService.getLevelsByBuildingAndUnitId(buildingId, buildingUnitId));
    }


}

