package org.nl.acs.device.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.nl.acs.device.service.DeviceExtraService;
import org.nl.acs.device.service.dto.DeviceExtraDto;
import org.nl.acs.device.service.dto.DeviceExtraQueryParam;
import org.nl.common.logging.annotation.Log;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
* @author jiaolm
* @date 2023-05-09
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "设备扩展管理")
@RequestMapping("/api/deviceExtra")
public class DeviceExtraController {

    private final DeviceExtraService deviceExtraService;

    @GetMapping
    @Log("查询设备扩展")
    @ApiOperation("查询设备扩展")
    //@PreAuthorize("@el.check('deviceExtra:list')")
    public ResponseEntity query(DeviceExtraQueryParam query, Pageable pageable){
        return new ResponseEntity<>(deviceExtraService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增设备扩展")
    @ApiOperation("新增设备扩展")
    //@PreAuthorize("@el.check('deviceExtra:add')")
    public ResponseEntity create(@Validated @RequestBody DeviceExtraDto resources){
        return new ResponseEntity<>(deviceExtraService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改设备扩展")
    @ApiOperation("修改设备扩展")
    //@PreAuthorize("@el.check('deviceExtra:edit')")
    public ResponseEntity update(@Validated @RequestBody DeviceExtraDto resources){
        deviceExtraService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

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

    /*
    @Log("导出设备扩展")
    @ApiOperation("导出设备扩展")
    @GetMapping(value = "/download")
    //@PreAuthorize("@el.check('deviceExtra:list')")
    public void download(HttpServletResponse response, DeviceExtraQueryParam query) throws IOException {
        deviceExtraService.download(deviceExtraService.queryAll(query), response);
    }*/

}
