package org.nl.acs.device.rest;

import org.nl.common.logging.annotation.Log;
import org.nl.acs.device.service.DeviceisonlineService;
import org.nl.acs.device.service.dto.DeviceisonlineDto;
import org.nl.acs.device.service.dto.DeviceisonlineQueryParam;
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/deviceisonline")
public class DeviceisonlineController {

    private final DeviceisonlineService deviceisonlineService;

    @GetMapping
    @Log("查询设备在线状态")
    @ApiOperation("查询设备在线状态")
    //@PreAuthorize("@el.check('deviceisonline:list')")
    public ResponseEntity query(DeviceisonlineQueryParam query, Pageable pageable){
        return new ResponseEntity<>(deviceisonlineService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增设备在线状态")
    @ApiOperation("新增设备在线状态")
    //@PreAuthorize("@el.check('deviceisonline:add')")
    public ResponseEntity create(@Validated @RequestBody DeviceisonlineDto resources){
        return new ResponseEntity<>(deviceisonlineService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改设备在线状态")
    @ApiOperation("修改设备在线状态")
    //@PreAuthorize("@el.check('deviceisonline:edit')")
    public ResponseEntity update(@Validated @RequestBody DeviceisonlineDto resources){
        deviceisonlineService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除设备在线状态")
    @ApiOperation("删除设备在线状态")
    //@PreAuthorize("@el.check('deviceisonline:del')")
    public ResponseEntity delete(@RequestBody Set<String> ids) {
        deviceisonlineService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出设备在线状态")
    @ApiOperation("导出设备在线状态")
    @GetMapping(value = "/download")
    //@PreAuthorize("@el.check('deviceisonline:list')")
    public void download(HttpServletResponse response, DeviceisonlineQueryParam query) throws IOException {
        deviceisonlineService.download(deviceisonlineService.queryAll(query), response);
    }*/

}
