package org.nl.acs.labeling_template.rest;

import org.nl.common.logging.annotation.Log;
import org.nl.acs.labeling_template.domain.LabelingTemplate;
import org.nl.acs.labeling_template.service.LabelingTemplateService;
import org.nl.acs.labeling_template.service.dto.LabelingTemplateDto;
import org.nl.acs.labeling_template.service.dto.LabelingTemplateQueryParam;
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/labelingTemplate")
public class LabelingTemplateController {

    private final LabelingTemplateService labelingTemplateService;

    @GetMapping
    @Log("查询贴标模板基本信息")
    @ApiOperation("查询贴标模板基本信息")
    //@PreAuthorize("@el.check('labelingTemplate:list')")
    public ResponseEntity query(LabelingTemplateQueryParam query, Pageable pageable){
        return new ResponseEntity<>(labelingTemplateService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增贴标模板基本信息")
    @ApiOperation("新增贴标模板基本信息")
    //@PreAuthorize("@el.check('labelingTemplate:add')")
    public ResponseEntity create(@Validated @RequestBody LabelingTemplateDto resources){
        return new ResponseEntity<>(labelingTemplateService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改贴标模板基本信息")
    @ApiOperation("修改贴标模板基本信息")
    //@PreAuthorize("@el.check('labelingTemplate:edit')")
    public ResponseEntity update(@Validated @RequestBody LabelingTemplateDto resources){
        labelingTemplateService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除贴标模板基本信息")
    @ApiOperation("删除贴标模板基本信息")
    //@PreAuthorize("@el.check('labelingTemplate:del')")
    public ResponseEntity delete(@RequestBody Set<String> ids) {
        labelingTemplateService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出贴标模板基本信息")
    @ApiOperation("导出贴标模板基本信息")
    @GetMapping(value = "/download")
    //@PreAuthorize("@el.check('labelingTemplate:list')")
    public void download(HttpServletResponse response, LabelingTemplateQueryParam query) throws IOException {
        labelingTemplateService.download(labelingTemplateService.queryAll(query), response);
    }*/

}
