package com.usky.iot.controller.web;


import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.iot.domain.BaseBuildFacility;
import com.usky.iot.service.BaseBuildFacilityService;
import com.usky.iot.service.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 建筑设施 前端控制器
 * </p>
 *
 * @author han
 * @since 2023-07-26
 */
@RestController
@RequestMapping("/baseBuildFacility")
public class BaseBuildFacilityController {
    @Autowired
    private BaseBuildFacilityService baseBuildFacilityService;

    /**
     * 新增
     * @param baseBuildFacility
     * @return
     */
    @PostMapping
    ApiResult<Void> add(@RequestBody BaseBuildFacility baseBuildFacility){
        baseBuildFacilityService.add(baseBuildFacility);
        return ApiResult.success();
    }

    /**
     * 修改
     * @param baseBuildFacility
     * @return
     */
    @PutMapping
    ApiResult<Void> update(@RequestBody BaseBuildFacility baseBuildFacility){
        baseBuildFacilityService.update(baseBuildFacility);
        return ApiResult.success();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    ApiResult<Void> remove(@PathVariable("id") Integer id){
        baseBuildFacilityService.remove(id);
        return ApiResult.success();
    }

    /**
     * 分页
     * @param requestVO
     * @return
     */
    @PostMapping("page")
    ApiResult<CommonPage<BaseBuildFacility>> page(@RequestBody BaseBuildFacilityRequestVO requestVO){
        return ApiResult.success(baseBuildFacilityService.page(requestVO));
    }

    /**
     * 建筑设施关联设备列表
     * @param requestVO
     * @return
     */
    @PostMapping("deviceList")
    ApiResult<CommonPage<BuildFacilityResponeVO>> deviceList(@RequestBody BuildFacilityRequestVO requestVO){
        return ApiResult.success(baseBuildFacilityService.deviceList(requestVO));
    }

    /**
     * 建筑设施设备详情信息
     * @param queryVO
     * @return
     */
    @PostMapping("facilityDeviceInfo")
    ApiResult<List<FacilityDeviceResultVO>> facilityDeviceInfo(@RequestBody FacilityDeviceQueryVO queryVO){
        return ApiResult.success(baseBuildFacilityService.facilityDeviceInfo(queryVO));
    }

    /**
     * 建筑设施设备绑定
     * @return
     */
    @PostMapping("setStatus")
    ApiResult<Void> setStatus(@RequestBody FacilityDeviceStatusVO statusVO){
        baseBuildFacilityService.setStatus(statusVO);
        return ApiResult.success();
    }
}

