package org.nl.acs.device.rest;

import org.nl.common.logging.annotation.Log;
import org.nl.acs.device.service.DeviceRunpointService;
import org.nl.acs.device.service.dto.DeviceRunpointDto;
import org.nl.acs.device.service.dto.DeviceRunpointQueryParam;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.util.Set;

/**
* @author jiaolm
* @date 2023-05-09
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "设备点位管理")
@RequestMapping("/api/deviceRunpoint")
public class DeviceRunpointController {

    private final DeviceRunpointService deviceRunpointService;

    @GetMapping
    @Log("查询设备点位")
    @ApiOperation("查询设备点位")
    //@PreAuthorize("@el.check('deviceRunpoint:list')")
    public ResponseEntity query(DeviceRunpointQueryParam query, Pageable pageable){
        return new ResponseEntity<>(deviceRunpointService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增设备点位")
    @ApiOperation("新增设备点位")
    //@PreAuthorize("@el.check('deviceRunpoint:add')")
    public ResponseEntity create(@Validated @RequestBody DeviceRunpointDto resources){
        return new ResponseEntity<>(deviceRunpointService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改设备点位")
    @ApiOperation("修改设备点位")
    //@PreAuthorize("@el.check('deviceRunpoint:edit')")
    public ResponseEntity update(@Validated @RequestBody DeviceRunpointDto resources){
        deviceRunpointService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除设备点位")
    @ApiOperation("删除设备点位")
    //@PreAuthorize("@el.check('deviceRunpoint:del')")
    public ResponseEntity delete(@RequestBody Set<String> ids) {
        deviceRunpointService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出设备点位")
    @ApiOperation("导出设备点位")
    @GetMapping(value = "/download")
    //@PreAuthorize("@el.check('deviceRunpoint:list')")
    public void download(HttpServletResponse response, DeviceRunpointQueryParam query) throws IOException {
        deviceRunpointService.download(deviceRunpointService.queryAll(query), response);
    }*/

}
