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.DeviceAssignedService;
import org.nl.acs.device.service.dto.DeviceAssignedDto;
import org.nl.acs.device.service.dto.DeviceAssignedQueryParam;
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/deviceAssigned")
public class DeviceAssignedController {

    private final DeviceAssignedService deviceAssignedService;

    @GetMapping
    @Log("查询设备任务分配信息")
    @ApiOperation("查询设备任务分配信息")
    //@PreAuthorize("@el.check('deviceAssigned:list')")
    public ResponseEntity query(DeviceAssignedQueryParam query, Pageable pageable){
        return new ResponseEntity<>(deviceAssignedService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增设备任务分配信息")
    @ApiOperation("新增设备任务分配信息")
    //@PreAuthorize("@el.check('deviceAssigned:add')")
    public ResponseEntity create(@Validated @RequestBody DeviceAssignedDto resources){
        return new ResponseEntity<>(deviceAssignedService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改设备任务分配信息")
    @ApiOperation("修改设备任务分配信息")
    //@PreAuthorize("@el.check('deviceAssigned:edit')")
    public ResponseEntity update(@Validated @RequestBody DeviceAssignedDto resources){
        deviceAssignedService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除设备任务分配信息")
    @ApiOperation("删除设备任务分配信息")
    //@PreAuthorize("@el.check('deviceAssigned:del')")
    public ResponseEntity delete(@RequestBody Set<String> ids) {
        deviceAssignedService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出设备任务分配信息")
    @ApiOperation("导出设备任务分配信息")
    @GetMapping(value = "/download")
    //@PreAuthorize("@el.check('deviceAssigned:list')")
    public void download(HttpServletResponse response, DeviceAssignedQueryParam query) throws IOException {
        deviceAssignedService.download(deviceAssignedService.queryAll(query), response);
    }*/

}
