package org.nl.acs.materialbase.rest;

import org.nl.common.logging.annotation.Log;
import org.nl.acs.materialbase.domain.Materialbase;
import org.nl.acs.materialbase.service.MaterialbaseService;
import org.nl.acs.materialbase.service.dto.MaterialbaseDto;
import org.nl.acs.materialbase.service.dto.MaterialbaseQueryParam;
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/materialbase")
public class MaterialbaseController {

    private final MaterialbaseService materialbaseService;

    @GetMapping
    @Log("查询物料基本信息")
    @ApiOperation("查询物料基本信息")
    //@PreAuthorize("@el.check('materialbase:list')")
    public ResponseEntity query(MaterialbaseQueryParam query, Pageable pageable){
        return new ResponseEntity<>(materialbaseService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增物料基本信息")
    @ApiOperation("新增物料基本信息")
    //@PreAuthorize("@el.check('materialbase:add')")
    public ResponseEntity create(@Validated @RequestBody MaterialbaseDto resources){
        return new ResponseEntity<>(materialbaseService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改物料基本信息")
    @ApiOperation("修改物料基本信息")
    //@PreAuthorize("@el.check('materialbase:edit')")
    public ResponseEntity update(@Validated @RequestBody MaterialbaseDto resources){
        materialbaseService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除物料基本信息")
    @ApiOperation("删除物料基本信息")
    //@PreAuthorize("@el.check('materialbase:del')")
    public ResponseEntity delete(@RequestBody Set<String> ids) {
        materialbaseService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出物料基本信息")
    @ApiOperation("导出物料基本信息")
    @GetMapping(value = "/download")
    //@PreAuthorize("@el.check('materialbase:list')")
    public void download(HttpServletResponse response, MaterialbaseQueryParam query) throws IOException {
        materialbaseService.download(materialbaseService.queryAll(query), response);
    }*/

}
