package org.nl.acs.device.rest;

import org.nl.common.logging.annotation.Log;
import org.nl.acs.device.service.DeviceDbitemService;
import org.nl.acs.device.service.dto.DeviceDbitemDto;
import org.nl.acs.device.service.dto.DeviceDbitemQueryParam;
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 = "设备DB项管理")
@RequestMapping("/api/deviceDbitem")
public class DeviceDbitemController {

    private final DeviceDbitemService deviceDbitemService;

    @GetMapping
    @Log("查询设备DB项")
    @ApiOperation("查询设备DB项")
    //@PreAuthorize("@el.check('deviceDbitem:list')")
    public ResponseEntity query(DeviceDbitemQueryParam query, Pageable pageable){
        return new ResponseEntity<>(deviceDbitemService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增设备DB项")
    @ApiOperation("新增设备DB项")
    //@PreAuthorize("@el.check('deviceDbitem:add')")
    public ResponseEntity create(@Validated @RequestBody DeviceDbitemDto resources){
        return new ResponseEntity<>(deviceDbitemService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改设备DB项")
    @ApiOperation("修改设备DB项")
    //@PreAuthorize("@el.check('deviceDbitem:edit')")
    public ResponseEntity update(@Validated @RequestBody DeviceDbitemDto resources){
        deviceDbitemService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

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

    /*
    @Log("导出设备DB项")
    @ApiOperation("导出设备DB项")
    @GetMapping(value = "/download")
    //@PreAuthorize("@el.check('deviceDbitem:list')")
    public void download(HttpServletResponse response, DeviceDbitemQueryParam query) throws IOException {
        deviceDbitemService.download(deviceDbitemService.queryAll(query), response);
    }*/

}
